¶à´°¿ÚÒì²½ÊÛÆ±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
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔǰ£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
×÷Õßͨ¹ýʹÓÃJAVAÖеĶ¯Ì¬´úÀíʵÏÖÊý¾Ý¿âÁ¬½Ó³Ø£¬Ê¹Ê¹ÓÃÕß¿ÉÒÔÒÔÆÕͨµÄjdbcÁ¬½ÓµÄʹÓÃϰ¹ßÀ´Ê¹ÓÃÁ¬½Ó³Ø¡£
Êý¾Ý¿âÁ¬½Ó³ØÔÚ±àдӦÓ÷þÎñÊǾ³£ÐèÒªÓõ½µÄÄ£¿é£¬Ì«¹ýƵ·±µÄÁ¬½ÓÊý¾Ý¿â¶Ô·þÎñÐÔÄÜÀ´½²ÊÇÒ»¸öÆ¿¾±£¬Ê¹Óûº³å³Ø¼¼Êõ¿ÉÒÔÀ´Ïû³ýÕâ¸öÆ¿¾±¡£ÎÒÃÇ¿ÉÒÔÔÚ»¥ÁªÍøÉÏÕÒµ½ºÜ¶à¹ØÓ ......