-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvokeWorkers.java
44 lines (38 loc) · 1.29 KB
/
invokeWorkers.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
37
38
39
40
41
42
43
44
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class invokeWorkers implements Runnable
{
/*************************/
int secondLevelThreads = 18;
/**************************/
public invokeWorkers() // Constructor to get arguments from the main thread
{
// Send args from main thread
}
ExecutorService executorService = Executors.newFixedThreadPool(secondLevelThreads) ;
public void run()
{
for(int i=0; i < secondLevelThreads ; i++)
{
Runnable runnableTask = new sendQuery() ; // Pass arg, if any to constructor sendQuery(arg)
executorService.submit(runnableTask) ;
}
sendQuery s = new sendQuery(); // Send queries from current thread
s.run();
// Stop further requests to executor service
executorService.shutdown() ;
try
{
// Wait for 8 sec and then exit the executor service
if (!executorService.awaitTermination(8, TimeUnit.SECONDS))
{
executorService.shutdownNow();
}
}
catch (InterruptedException e)
{
executorService.shutdownNow();
}
}
}