CDC和FP都可以正常编译通过,我需要对其功能作简单的测试:
用三个case:
case1:
CDCTest.java
#####################################################################################
public class CDCTest
{
public static void main(String[] args)
{
TicketSell sell = new TicketSell();
new Thread(sell).start();
new Thread(sell).start();
new Thread(sell).start();
new Thread(sell).start();
}
}
class TicketSell implements Runnable
{
int tickets = 500;
Object o = new Object();
public void run()
{
while(true)
{
synchronized (o)
{
if (tickets > 0)
{
try
{
Thread.sleep(10);
System.out.println(Thread.currentThread().getName() + " sells the " + tickets + " ticket!");
tickets--;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
}
}
#####################################################################################
case2:
UDPSend.java 和 UDPReceive.java.
case 3:
TCPServer.java 和 TCPClient.java
case1和case2可以在CDC下正确运行,说明CDC类库已经支持线程和UDP的Socket类,而case3只能在FP下才能正常运行,因为ServerSocket类在FP类库中包含。
用三个case:
case1:
CDCTest.java
#####################################################################################
public class CDCTest
{
public static void main(String[] args)
{
TicketSell sell = new TicketSell();
new Thread(sell).start();
new Thread(sell).start();
new Thread(sell).start();
new Thread(sell).start();
}
}
class TicketSell implements Runnable
{
int tickets = 500;
Object o = new Object();
public void run()
{
while(true)
{
synchronized (o)
{
if (tickets > 0)
{
try
{
Thread.sleep(10);
System.out.println(Thread.currentThread().getName() + " sells the " + tickets + " ticket!");
tickets--;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
}
}
#####################################################################################
case2:
UDPSend.java 和 UDPReceive.java.
case 3:
TCPServer.java 和 TCPClient.java
case1和case2可以在CDC下正确运行,说明CDC类库已经支持线程和UDP的Socket类,而case3只能在FP下才能正常运行,因为ServerSocket类在FP类库中包含。