Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请教高手("原子类型"指的是什么?)
alan105





发贴: 4
积分: 0
于 2006-06-22 10:17 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在定义成员方法时,方法名前面的类型标识符可以是所有的原子类型,这时的"原子类型"指的是什么?

还有就是int和char相容吗?


why edited on 2006-06-22 17:18

作者 Re:请教高手("原子类型"指的是什么?) [Re:alan105]
bluecrystal





发贴: 2788991
积分: 48
于 2006-06-23 00:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
原子类型应该就是指java内置的数据类型


Just Software & Travel
-- 我的blog -- 技术点滴/经验分享
作者 Re:请教高手("原子类型"指的是什么?) [Re:alan105]
ftang



版主


发贴: 214
积分: 38
于 2006-06-23 01:58 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Atomicity:
不好意思没有找到定义,只能给出我的理解了,就是对一个原子类型的操作是不会被另外一个线程所打断.

在JAVA里面所谓”内置“数据类型有几类是原子类型的,但是long 和 double 不是,因为他们的长度是64位,而JVM内存处理在32位,所以long和 double 不是原子类型,切记,切记
--> 原子类型应该就是指java内置的数据类 <-- 是不对的

给出一段代码

public class BreakDouble extends Thread
{

final static double VAL1 = 0;
final static String VAL1S = Double.toString(VAL1);
final static double VAL2 = Double.MAX_VALUE;
final static String VAL2S = Double.toString(VAL2);

static double test = VAL1;

public static void main( String[] args )
{

System.out.println("VAL1 = " + VAL1S );
System.out.println("VAL2 = " + VAL2S );
System.out.println("\nErrors:");

for (int i=0; i<10;i++) {
BreakDouble t = new BreakDouble();
t.start();
}
}

public void run()
{
for( ;; )
{
double tmp=test;
test = VAL1;
String tmpTest=Double.toString(tmp);
if( (!tmpTest.equals(VAL1S)) && (!tmpTest.equals(VAL2S)) )
{
System.out.println("test = " + tmpTest );
}
test = VAL2;
}
}
}

pi178c1n5 /ms/user/shen/temp 196$ java BreakDouble
VAL1 = 0.0
VAL2 = 1.7976931348623157E308

Errors:
test = 2.1219957905E-314
test = 1.7976922776554302E308
test = 2.1219957905E-314
test = 1.7976922776554302E308



作者 Re:请教高手("原子类型"指的是什么?) [Re:ftang]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-06-23 09:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这里的“原子类型”也许是primitive type的翻译吧


作者 Re:请教高手("原子类型"指的是什么?) [Re:alan105]
alan105





发贴: 4
积分: 0
于 2006-06-23 10:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢各位指教啊


作者 Re:请教高手("原子类型"指的是什么?) [Re:alan105]
ftang



版主


发贴: 214
积分: 38
于 2006-06-23 21:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
个人感觉把primitive type翻译成原子类型是非常不负责任的, 翻译的人不懂瞎翻还不如不翻,让大家看原版的呢


作者 Re:请教高手("原子类型"指的是什么?) [Re:alan105]
jerryikitty





发贴: 13
积分: 1
于 2006-06-27 11:57 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
原子是JDK1。5中的新特性。引用:“java.util.concurrent.atomic 包中提供了原子变量的 9 种风格( AtomicInteger; AtomicLong; AtomicReference; AtomicBoolean;原子整型;长型;引用;及原子标记引用和戳记引用类的数组形式,其原子地更新一对值)。

原子变量类可以认为是 volatile 变量的泛化,它扩展了可变变量的概念,来支持原子条件的比较并设置更新。读取和写入原子变量与读取和写入对可变变量的访问具有相同的存取语义。


http://www-128.ibm.com/developerworks/cn/java/j-jtp11234/




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923