Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

java²¢·¢±à³Ìʵ¼ù ±Ê¼Ç£¨1£©

Ḭ̈߳²È« ʲôÊÇḬ̈߳²È«(thread-safe)£¿ Ò»¸öÀ࣬Èç¹ûÄܹ»ÔÚ¶àÏ̲߳¢·¢·ÃÎʵĻ·¾³Ï£¨²»¹ÜÏ̷߳ÃÎʵÄ˳Ðò£©ÕýÈ·±íÏÖ×Ô¼ºµÄÐÐΪ£¬²¢ÇÒÎÞÐèÍⲿµ÷ÓÃÌí¼ÓÈκÎͬ²½Ö®ÀàµÄ²Ù×÷£¬Õâ¸öÀà¾ÍÊÇḬ̈߳²È«µÄ¡£
Õâ¸öÕýÈ·ÐÔ¿ÉÒÔÕâôÀí½â£¬¾ÍÊÇ˵¶àÏ̷߳ÃÎʵĽá¹û²»»á²»Í¬ÓÚµ¥Ï̵߳ķÃÎÊ¡£
Ḭ̈߳²È«µÄÀ಻ÐèÒªÍⲿµ÷ÓÃÌṩÈκθ½¼ÓµÄͬ²½¡£ ÎÞ״̬(stateless)µÄÀàÓÀÔ¶ÊÇḬ̈߳²È«µÄ¡£
ʲôÊÇÎÞ״̬µÄÀࣿûÓÐʵÀý±äÁ¿(field)£¬Ò²Ã»ÓÐÒýÓÃÆäËüÀàµÄfield¡£ Ô­×ÓÐÔ A race condition occurs when the correctness of a computation depends on the relative timing or interleaving of multiple threads by the runtime; in other words, when getting the right answer relies on lucky timing. ×î³£¼ûµÄrace conditionÊÇcheck-and-act¡£Òª·ÀÖ¹ÕâÖÖrace condition£¬ÎÒÃÇÐèÒªÔ­×ÓÐԵIJÙ×÷¡£Ê²Ã´ÊÇÔ­×ÓÐÔÄØ£¬¾ÍÊÇ˵£¬ÄãÕâ¸ö²Ù×÷ÔÚÖ´ÐеĹý³ÌÖУ¬¶ÔÓÚÄã²Ù×÷µÄ״̬ÉÏÆäËüµÄ²Ù×÷£¨°üÀ¨Äã×Ô¼º£©ÒªÃ´È«¶¼Ö´ÐÐÍêÁË£¬ÒªÃ´»¹Ã»¿ªÊ¼¡£
Ïë˵¾äͨ˳µÄÖйú»°ÔõôÕâôÄѰ¡£¬»¹ÊǸø³öÔ­Îİɣº Operations A and B are atomic with respect to each other if, from the perspective of a thread executing A, when another thread executes B, either all of B has executed or none of it has. An atomic operation is one that is atomic with respect to all operations, including itself, that operate on the same state. À´¸öÀý×Ó @NotThreadSafe
public class UnsafeCountingFactorizer implements Servlet {
private long count = 0;
public long getCount() { return count; }
public void service(ServletRequest req, ServletResponse resp) {
BigInteger i = extractfromRequest(req);
BigInteger[] factors = factor(i);
++count;
encodeIntoResponse(resp, factors);
}
}
@ThreadSafe
public class CountingFactorizer implements Servlet {
private final AtomicLong count = new AtomicLong(0);
public long getCount() { return count.get(); }
public void service(ServletRequest req, ServletResponse resp) {
BigInteger i = extractfromRequest(req);
BigInteger[] factors = factor(i);
count.incrementAndGet();


Ïà¹ØÎĵµ£º

javaѧϰ·½·¨×ܽá

Èç¹ûÄãjavaÒѾ­ÈëÃÅÁË£¬½¨ÒéÄãÏȲ»È¥Ïë´úÂë¡£¶øÊÇÈ¥ÏëÍê³ÉÈÎÎñÒª×öµÄ²½Öè¡£ÏëºÃÁ˺óÄÄÅÂÄãÈ¥Õ³Ìù´úÂë¶¼¿ÉÒÔ¡£±à³ÌÊÇ¿¼ÑéµÄ˼ά£¬²»ÊÇд´úÂëµÄËÙ¶È£¬ºÍ¶Ô´úÂëµÄ¼ÇÒäÐÔ¡£
±à³ÌÊÇÒ»¼þ¾­Ñé»î, ²»ÊÇ¿´ÊéÄܽâ¾öµÄ, ±à³ÌÖÐÓöµ½µÄÎÊÌâÇ§Ææ°Ù¹Ö, ¸ù±¾²»ÊÇÒ»±¾Êé»òÕßn±¾ÄܸøÄã½â¾öµÄ£¬±ØÐë×Ô¼ºÇ××ÔÈ¥Ìå»á
 
ËùÒÔ, ÕÒ±¾ÓÐʵÀýµ ......

[ת]Does Java pass by reference or pass by value?

http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html
Does Java pass by reference or pass by value?
Why can't you swap in Java?
By Tony
Sintes, JavaWorld.com, 05/26/00

Print
Email
Feedback
Resources
Discuss
(76)
Digg
Reddit
SlashDot
Stumble
......

Scooter Framework; Java¤ËCRUD¤È¥·¥ó¥×¥ë¤µ¤òÌṩ

ÏÂÎÄÊÇÈÕ±¾ÈË·­ÒëµÄÀÏÍâµÄÎÄÕ£¬ÈÕ±¾ÓÐÒ»°ïÈËÔÚ³´Ruby£¬ºÃÏñÊÇÈÕ±¾ÈË·¢Ã÷µÄ£¬Èç¹û¹Ø×¢µÄÈ˶àÁËÒ²ÓпÉÄÜÔÚÒ»¶¨µÄ·¶Î§ÄÚÁ÷ÐÐÆðÀ´¡£
´ËÎĽéÉÜÁËScooter framework¿ò¼Ü£¬ÊÇ»ùÓÚRuby on Rails ¹¹ÖþµÄ£¬ÊÇÒ»¸öSSH¿ª·¢¼¯³ÉµÄÌæ´úÆ·£¬Óõ½ÁËJAVAµÄһЩµ×²ã¼¼Êõ£¬ÓкܶàеĸÅÄ1.0°æ±¾Ô¤¼Æ½ñÄê6£¬7Ô·ݷ¢²¼¡£Ã²Ëƹ¦ÄܺÜÇ¿´ó£¬¸ÐÐ ......

java tips

1£¬intÓëbytes ת»»
intת»»³Ébytes
public
static
final
byte
[]
int2bytes
(
int
value
)

{
return
new
byte
[]

{
(
byte
)(
value
>>>
24
),
(
byte
)(
value
>>>
16
),
......

java Êý×é²Ù×÷£¬´ÓÊý×éaÖÐɾ³ýÊý×ébÖдæÔÚµÄÔªËØ

 //´ÓÊý×éaÖÐɾ³ýÊý×ébÖдæÔÚµÄÔªËØ
 String stra[] = {"g","b","c","h","k"};//ԭʼÊý×é
  String strb[] = {"g","k"};   //ÒÆ³ýµÄÔªËØ
  ArrayList list = new ArrayList();
//·½·¨Ò»
  for(int i=0;i<stra.length;i++){
   int n=0;
  ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ