¶à´°¿ÚÒì²½ÊÛÆ±java¾À´í
ÕâÊÇ·þÎñ´°¿ÚÀ࣬ģÄâËĸöÏß³ÌÒì²½ÔËÐÐ
public class TicketWindow {
public static void main(String args[]) {
Ticket ticket = new Ticket();
Thread w1 = new Thread(ticket, "1ºÅÊÛÆ±´°¿Ú");
Thread w2 = new Thread(ticket, "2ºÅÊÛÆ±´°¿Ú");
Thread w3 = new Thread(ticket, "3ºÅÊÛÆ±´°¿Ú");
Thread w4 = new Thread(ticket, "4ºÅÊÛÆ±´°¿Ú");
w1.setPriority(Thread.NORM_PRIORITY);
w2.setPriority(Thread.NORM_PRIORITY);
w3.setPriority(Thread.NORM_PRIORITY);
w4.setPriority(Thread.NORM_PRIORITY);
w1.start();
w2.start();
w3.start();
w4.start();
}
}
ÒÔÏÂÊÇticketÀ࣬¿ØÖÆ´°¿Ú³öƱµÄÂß¼
public class Ticket implements Runnable {
private int ticketNumber = 1;
public void sellTicket() {
while (ticketNumber++ < 100) {
synchronized (this) {
System.out.println(Thread.currentThread().getName() + "ÕýÔÚÊÛ³öµÚ"
+ ticketNumber + "ÕÅÆ±");
}
}
}
public void run() {
sellTicket();
}
}
ÔËÐÐÀàTicketWindow£¬
²¿·Ö½á¹ûÈçÏ£º
1ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ2ÕÅÆ±
2ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ5ÕÅÆ±
4ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ6ÕÅÆ±
3ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ7ÕÅÆ±
3ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ8ÕÅÆ±
3ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ9ÕÅÆ±
2ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ11ÕÅÆ±
4ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ11ÕÅÆ±
¡£¡£¡£
2ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ101ÕÅÆ±
1ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ102ÕÅÆ±
4ºÅÊÛÆ±´°¿ÚÕýÔÚÊÛ³öµÚ103ÕÅÆ±
°´ÔËÐÐÇé¿öÀ´¿´£¬´æÔÚÈý¸öÎÊÌ⣺
1.³öƱ²»Á¬Ðø----ƱºÅÓмä¶Ï
2.ƱºÅÖØ¸´--²»Í¬´°¿ÚÊÛ³öÖØÍ¬Ò»Æ±ºÅ
3.¶àÂôƱ--Âô³öƱÊý³¬¹ý100
ÒÔÏÂÊÇÕýÈ·µÄ´úÂ룺
public class Ticket implements Runnable {
private int ticketNumber = 1;
public void sellTicket() {
while (ticketNumber < 100) {//ƱºÅµÝÔö²Ù×÷Ó¦ÊôÓÚÁÙ½çÇø£¬Ðë·ÅÔÚsynchronizedÓï¾ä¿éÄÚ /
synchronized (this) {
if (ticketN
Ïà¹ØÎĵµ£º
---09 11 29---
Servlet&ServletÈÝÆ÷:
Java Servlet(Java·þÎñÆ÷С³ÌÐò)ÊÇÒ»¸ö»ùÓÚJava¼¼ÊõµÄС³ÌÐò,
ÔËÐÐÔÚ·þÎñÆ÷¶Ë,ÓÉServletÈÝÆ÷Ëù¹ÜÀí,ÓÃÓÚÉú³É¶¯Ì¬µÄÄÚÈÝ.
ServletÊÇÆ½Ì¨¶ÀÁ¢µÄJavaÀà,ËùÒÔ±àдһ¸öServletʵ¼ÊÉϾÍÊǰ´
ÕÕservlet¹æ·¶±àдһ¸öJavaÀà.
ServletÈÝÆ÷Ò²½Ð×öServletÒýÇæ,ÊÇweb·þÎñÆ÷»òÓ¦Óà ......
ÌâÄ¿£ºÇëÓöàÏß³ÌʵÏÖÒ»¸öÉú²úÕßÀàºÍÒ»¸öÏû·ÑÕßÀ࣬Éú²úÕßËæ»úÉú³É20¸ö×Ö·û£¬Ïû·ÑÕß½«×Ö·û´òÓ¡µ½¿ØÖÆÌ¨¡£
class SyncStack{ //ͬ²½¶ÑÕ»Àà
¡¡¡¡¡¡private int index = 0; //¶ÑÕ»Ö¸Õë³õʼֵΪ0
¡¡¡¡¡¡private char []buffer = new char[6]; //¶ÑÕ»ÓÐ6¸ö×Ö·ûµÄ¿Õ¼ä
¡¡¡¡¡¡public synchronized void push(char c){ //¼ÓÉ ......
ת×Ôhttp://hi.baidu.com/oyamao/blog/item/bcc75d5128468868843524eb.html
Òì³£´¦ÀíÊdzÌÐòÉè¼ÆÖÐÒ»¸ö·Ç³£ÖØÒªµÄ·½Ã棬ҲÊdzÌÐòÉè¼ÆµÄÒ»´óÄѵ㣬´ÓC¿ªÊ¼£¬ÄãÒ²ÐíÒѾ֪µÀÈçºÎÓÃif...else...À´¿ØÖÆÒì³£ÁË£¬Ò²ÐíÊÇ×Ô·¢µÄ£¬È»¶øÕâÖÖ¿ØÖÆÒ쳣ʹ¿à£¬Í¬Ò»¸öÒì³£»òÕß´íÎóÈç¹û¶à¸öµØ·½³öÏÖ£¬ÄÇôÄãÿ¸öµØ·½¶¼Òª×öÏàͬ´¦Àí£¬¸Ð¾õÏൠ......
ÎÒÃÇÖªµÀ£¬ÔÚJavaÖÐÉèÖñäÁ¿ÖµµÄ²Ù×÷£¬³ýÁËlongºÍ doubleÀàÐ͵ıäÁ¿Íâ¶¼ÊÇÔ×Ó²Ù×÷£¬Ò²¾ÍÊÇ˵£¬¶ÔÓÚ±äÁ¿ÖµµÄ¼òµ¥¶Áд²Ù×÷ûÓбØÒª½øÐÐͬ²½¡£ÕâÔÚJVM 1.2֮ǰ£¬JavaµÄÄÚ´æÄ£ÐÍʵÏÖ×ÜÊÇ´ÓÖ÷´æ¶ÁÈ¡±äÁ¿£¬ÊDz»ÐèÒª½øÐÐÌØ±ðµÄ×¢ÒâµÄ¡£¶øËæ×ÅJVMµÄ³ÉÊìºÍÓÅ»¯£¬ÏÖÔÚÔÚ¶àÏ̻߳·¾³ÏÂvolatile¹Ø¼ü×ÖµÄʹÓñäµÃ·Ç³£ÖØÒª¡£ÔÚµ±Ç°µ ......
//¼ÆËãÌìÊý
public List day(String dates,String datee) throws ParseException{
List dayls=new ArrayList();
// ×Ö·û´®×ª»»³ÉÈÕÆÚ
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = format.parse(dates);
&nb ......