Java Reference
In-Depth Information
{
System.out.println("CounterClient.start");
Counter c1 = (Counter)ctx.lookup("Counter1");
if(c1 != null && thread1 == null)
{
thread1 = new CounterThread("client1", c1, 7000);
thread1.start();
}
Counter c2 = (Counter)ctx.lookup("Counter2");
if(c2 != null && thread2 == null)
{
thread2 = new CounterThread("client2", c2, 5000);
thread2.start();
}
}
@Stop
public void stop()
{
System.out.println("CounterClient.stop");
if(thread1 != null)
{
thread1.interrupt();
try
{
thread1.join();
}
catch(InterruptedException e)
{
}
thread1 = null;
}
if(thread2 != null)
{
thread2.interrupt();
try
{
thread2.join();
}
catch(InterruptedException e)
{
}
thread2 = null;
}
}
}
class CounterThread extends Thread
{
private Counter c;
private long sleepTime;
public CounterThread(String name, Counter c, long sleepTime)
{
super(name);
this.c = c;
this.sleepTime = sleepTime;
}
 
Search WWH ::




Custom Search