Java Reference
In-Depth Information
public RunnableHelloCount()
{
//Since current object implements Runnable , it can
//be used as the argument to the Thread
//constructor for each of the member threads…
thread1 = new Thread(this);
thread2 = new Thread(this);
thread1.start();
thread2.start();
}
public void run()
{
int pause;
for (int i=0; i<10; i++)
{
try
{
System.out.println(
Thread.currentThread().getName()
+ " being executed.");
pause = (int)(Math.random()*3000);
Thread.sleep(pause);
}
catch (InterruptedException interruptEx)
{
System.out.println(interruptEx);
}
}
}
}
3.3
Multithreaded Servers
There is a fundamental and important limitation associated with all the server pro-
grams encountered so far:
￿
they can handle only one connection at a time.
This restriction is simply not feasible for most real-world applications and would
render the software useless. There are two possible solutions:
￿
use a non-blocking server;
￿
use a multithreaded server.
Search WWH ::




Custom Search