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

JAVA and C++°æÐźÅÁ¿£¨PV²Ù×÷£©

import java.util.concurrent.Semaphore;
/**
* ³éÏóÈÎÎñ£¬¾ßÌåµÄÖ´ÐÐÈÎÎñ£¬¹éʵÏÖÀฺÔð
*
* @author Administrator
*
*/
public abstract class Task {
public abstract void run();
private Semaphore s;
private boolean hasExisted = false;
public void P(final Semaphore s) throws InterruptedException {
if (s == null) { // ÉêÇë¿ÕµÄÐźÅÁ¿
throw new InterruptedException("²»ÄÜΪ¿Õ");
}
if (hasExisted) {// ÒѾ­ÉêÇëÁËÒ»¸ö×ÊÔ´£¬»¹Ã»ÓÐÊÍ·Å
throw new InterruptedException("ÒѾ­Õ¼ÓÃÒ»¸ö×ÊÔ´");
}
s.acquire();// ×èÈû
this.s = s;
hasExisted = true;
}
public boolean V() {
if (!hasExisted) {
return false;// ûմÓÐ×ÊÔ´¾Í²»ÄÜ˵ÊÍ·ÅÁË
}
s.release();//ÊÍ·Å×ÊÔ´
hasExisted = false;
s = null;
return true;
}
}
import java.util.concurrent.Semaphore;
/**
* ÓÃÐźÅÁ¿ÊµÏÖ»¥³â
*
* @author Administrator
*
*/
public class Mutex extends Semaphore {
private static final long serialVersionUID = 1L;
public Mutex() {
super(1);//»¥³âÊÇ1
}
} import java.util.concurrent.Semaphore;
public class Test {
public static void main(String[] args) {
// final Semaphore s = new Semaphore(2);//ÐźÅÁ¿£¬Ö´Ðнá¹ûrun the task1 run the
// task2 run the task3
final Semaphore s = new Mutex();// »¥³â run the task1 run the task2 run
// the task3
new Thread() {
public void run() {
Task1 task2 = new Task1();
try {
task2.P(s);// ÉêÇë×ÊÔ´
task2.run();// Ö´ÐÐÈÎÎñ
task2.V();// ÊÍ·Å×ÊÔ´
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
Task2 task2 = new Task2();
try {
task2.P(s);
task2.run();
task2.V();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
Task3 task2 = new Task3();
try {
task2.P(s);
task2.run();
task2.V();
} catch (InterruptedException e)


Ïà¹ØÎĵµ£º

Java¶àÏ̱߳à³ÌÏê½â


Ò»¡¢Àí½â¶àÏß³Ì
    ¶àÏß³ÌÊÇÕâÑùÒ»ÖÖ»úÖÆ£¬ËüÔÊÐíÔÚ³ÌÐòÖв¢·¢Ö´Ðжà¸öÖ¸ÁîÁ÷£¬Ã¿¸öÖ¸ÁîÁ÷¶¼³ÆΪһ¸öỊ̈߳¬±Ë´Ë¼ä»¥Ïà¶ÀÁ¢¡£Ïß³ÌÓÖ³ÆΪÇáÁ¿¼¶½ø³Ì£¬ËüºÍ½ø³ÌÒ»ÑùÓµÓжÀÁ¢µÄÖ´ÐпØÖÆ£¬ÓɲÙ×÷ϵͳ¸ºÔðµ÷¶È£¬Çø±ðÔÚÓÚÏß³ÌûÓжÀÁ¢µÄ´æ´¢¿Õ¼ä£¬¶øÊǺÍËùÊô½ø³ÌÖеÄÆäËüÏ̹߳²ÏíÒ»¸ö´æ´¢¿Õ¼ä£¬ÕâʹµÃÏ̼߳äµÄ ......

java¸ß¼¶¶àÏ̱߳à³Ì ¹ØÓÚÏ̵߳ÄÍ£Ö¹ÎÊÌâ(ת)

¶àÏß³ÌÊÇjavaµÄÒ»¸öÓÅÊÆ£¬javaʹµÃ³ÌÐòÔ±¿ÉÒԺܷ½±ãµÄ½øÐжàÏ̳߳ÌÐò¿ª·¢¡£»ñµÃ¸üºÃµÄÐÔÄÜ¡£
¹ØÓÚ¶àÏ̵߳ĸÅÄîÒÔ¼°Ò»°ãµÄ¶àÏ̱߳à³Ì£¬±ÈÈçÈçºÎÒÔ¼°ÎªºÎʵÏÖrunnable½Ó¿Ú£¬ÎªºÎstop()»á±»DeprecatedµôµÈµÈ£¬Õâ¸öÇë¿´matrix֮ǰµÄ¶àÏ̱߳à³Ì»ù´¡»òÕßsunµÄjavaÎĵµ¡£
¹ØÓÚ¶àÏ̱߳à³Ì£¬Óм¸µãÕâÀïÒªÌáµ½µÄ£º
1¡£¼ÈÈ»stop( ......

java ¼¯ºÏ—— ×ܽá1£¨²¿·ÖÐèÒª¼ÌÐøÍêÉÆ£©


£¨1£©À༯µÄ²úÉúÄ¿µÄ
À༯¼òµ¥À´½²¾ÍÊÇÒ»¸ö¶¯Ì¬µÄ¶ÔÏóÊý×飬´Ë¶ÔÏóÊý×é¿ÉÒԸıä´óС£¬¿ÉÒÔÈÎÒâµÄʵÏÖ¶ÔÏóµÄÔö¼Ó¡¢É¾³ý¡¢Êä³ö¡£ËùÓеÄÀ༯´æ·Åjava.util°üÖС£
£¨2£©À༯µÄ»®·Ö 
1¡¢´æ·Åµ¥Öµ£ºCollection 
2¡¢´æ·ÅÒ»¶ÔÖµ£ºMap 
3¡¢Êä³ö£ºIterator
Collection£¨´æ·Åµ¥Öµ£©
©ÀList
©¦©ÀLinkedList
© ......

JavaÃæÊÔÌâ


1.³éÏó£º
¡¡¡¡³éÏó¾ÍÊǺöÂÔÒ»¸öÖ÷ÌâÖÐÓ뵱ǰĿ±êÎ޹صÄÄÇЩ·½Ã棬ÒÔ±ã¸ü³ä·ÖµØ×¢ÒâÓ뵱ǰĿ±êÓйصķ½Ãæ¡£³éÏó²¢²»´òËãÁ˽âÈ«²¿ÎÊÌ⣬¶øÖ»ÊÇÑ¡ÔñÆäÖеÄÒ»²¿·Ö£¬ÔÝʱ²»Óò¿·Öϸ½Ú¡£³éÏó°üÀ¨Á½¸ö·½Ã棬һÊǹý³Ì³éÏ󣬶þÊÇÊý¾Ý³éÏó¡£
2.¼Ì³Ð£º
¡¡¡¡¼Ì³ÐÊÇÒ»ÖÖÁª½áÀàµÄ²ã´ÎÄ£ÐÍ£¬²¢ÇÒÔÊÐíºÍ¹ÄÀøÀàµÄÖØÓã¬ËüÌṩÁËÒ»ÖÖÃ÷È· ......

Java EE 6ÔöÇ¿µÄ¿ÉÀ©Õ¹ÐÔ£ºWeb·ÖƬºÍ¿É²å°Î¿ò¼Ü


   Java EE 6ÖÐ×îÒýÈËעĿµÄ¸Ä½øÒªËãWeb²ãµÄչʾÁË£¬ÕýÈçÇ°ÃæÌáµ½µÄJava EE 6µÄÒ»¸öÖØҪĿ±ê¾ÍÊÇÌá¸ß¿ÉÀ©Õ¹ÐÔ£¬ÔÚ¿ÉÀ©Õ¹ÐÔ·½ÃæÁ½¸ö¹Ø¼ü¸Ä½ø·Ö±ðÊÇWeb·ÖƬºÍ¿É²å°ÎÐÔ¹²Ïí¿ò¼Ü£¬ÕâÁ½¸öÐÂÌØÐÔÊÇͨ¹ýJava EE 6ÖеÄServlet 3.0¼¼ÊõÌṩµÄ¡£Servlet 3.0£¬JSR 315¹æ·¶ÊÇServlet¼¼ÊõµÄ×îа汾£¬ËüÌṩÁËÖîÈçÖ§³ÖÒì²½´¦ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ