日期:2014-05-20 浏览次数:20705 次
public class Shop
{
public static void main(String[] args)
{
Outer o=new Outer();
o.getSale("s1:").start();
o.getSale("s2:").start();
}
}
class Outer
{
private int ticket=20;
public Thread getSale(String s)
{
return new Sale(s);
}
private class Sale extends Thread
{
Sale(String s)
{
super(s);
}
public synchronized void run()
{
//int tmp=ticket;
while(ticket>0)
{
try {
sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(getName()+" ticket "+ticket--);
//ticket=tmp;
}
}
}
}
package cn.dzr.thread;
public class SocketTest
{
public static void main(String[] args)
{
Outer o=new Outer();
o.getSale("s1:").start();
o.getSale("s2:").start();
}
}
class Outer
{
public Thread getSale(String s)
{
return new Sale(s);
}
private class Sale extends Thread
{
Sale(String s)