Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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();


Ïà¹ØÎĵµ£º

´«ÖDz¥¿ÍJavaÅàѵ HTML»ù´¡

½ñÌìÊÇдµÚһƪ´«ÖDz¥¿Í½Ì³ÌÈÕÖ¾£¬Ò²ÊÇÎÒ¿´
JavaScript
ÊÓƵµÄµÚÒ»Ìì¡£
ÏÈ˵ԵÓÉ°É¡£´óÈý»¹ÓÐÈý¸öÔ¾ÍÒª½áÊøÁË£¬¿ÉÎÒ»¹Ã»Óиоõµ½×Ô¼ºÄܹ»ÓÐ×ã¹»µÄÄÜÁ¦ÕÒµ½·ÝºÃ¹¤×÷£¬´óѧÆÚ¼äѧµ½µÄ¶¼ÊÇЩƤëºÍÀíÂÛ£¬ÎÒ²»Ïëµ½ÁËÕÒ¹¤×÷µÄʱºò£¬ÃæÊÔ¹ÙÎÊÎÒ»á
XXX
Âð£¿ÎÒ˵²»»á¡£Òò´ËÎÒÏëͨ¹ýÅàѵÔö¼Ó×Ô¼ºµÄ¾ºÕùÁ¦¡£ÎÒ±¨Á˱¾µØµÄÒ»¼Ò
I ......

[ת]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 SWT ´°¿Ú¾ÓÖжÔÆë

public static void CentreWnd(Shell shell){
int width = shell.getMonitor().getClientArea().width;
int height = shell.getMonitor().getClientArea().height;
int x = shell.getSize().x;
int y = shell.getSize().y;
if (x > width) {
shell.getSize().x = width;
}
if (y > height) ......

Javaµ¥Àýģʽ


¡¡1¡¢¶öººÊ½
¡¡¡¡package singleton;
¡¡¡¡/**
¡¡¡¡* ¶öººÊ½µ¥Àý
¡¡¡¡* @author ½¯Ã÷Ô­
¡¡¡¡*
¡¡¡¡*/
¡¡¡¡public class HungrySingleton {
¡¡¡¡/**jvm±£Ö¤instanceÖ»±»³õʼ»¯Ò»´Î*/
¡¡¡¡private static HungrySingleton instance = new HungrySingleton();
¡¡¡¡/**×èÖ¹ÍⲿʹÓÃnewʵÀý»¯¶ÔÏó*/
¡¡¡¡private Hun ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ