-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.java
36 lines (32 loc) · 1.11 KB
/
client.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.concurrent.ExecutorService ;
import java.util.concurrent.Executors ;
import java.util.concurrent.TimeUnit;
import java.io.IOException ;
public class client
{
public static void main(String args[])throws IOException
{
/**************************/
int firstLevelThreads = 5 ; // Indicate no of users
/**************************/
// Creating a thread pool
ExecutorService executorService = Executors.newFixedThreadPool(firstLevelThreads);
for(int i = 0; i < firstLevelThreads; i++)
{
Runnable runnableTask = new invokeWorkers(); // Pass arg, if any to constructor sendQuery(arg)
executorService.submit(runnableTask) ;
}
executorService.shutdown();
try
{ // Wait for 8 sec and then exit the executor service
if (!executorService.awaitTermination(100, TimeUnit.SECONDS))
{
executorService.shutdownNow();
}
}
catch (InterruptedException e)
{
executorService.shutdownNow();
}
}
}