15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.ant.taskdefs; |
18 package com.nokia.ant.taskdefs; |
19 |
19 |
|
20 import java.util.concurrent.ExecutorService; |
|
21 import java.util.concurrent.Executors; |
|
22 import java.util.concurrent.ThreadPoolExecutor; |
|
23 |
|
24 import org.apache.tools.ant.BuildException; |
20 import org.apache.tools.ant.taskdefs.ExecTask; |
25 import org.apache.tools.ant.taskdefs.ExecTask; |
21 import org.apache.tools.ant.BuildException; |
|
22 |
|
23 import java.util.concurrent.*; |
|
24 |
26 |
25 /** |
27 /** |
26 * Exec task using shared thread pool |
28 * Exec task using shared thread pool |
27 * @ant.task name="exec" |
29 * @ant.task name="exec" |
28 */ |
30 */ |
37 * Submit exec into pool and throw exceptions |
39 * Submit exec into pool and throw exceptions |
38 */ |
40 */ |
39 public void execute() |
41 public void execute() |
40 { |
42 { |
41 String property = getProject().getProperty("number.of.threads"); |
43 String property = getProject().getProperty("number.of.threads"); |
42 if (property != null) |
44 if (property != null) { |
43 { |
|
44 ((ThreadPoolExecutor)threadPool).setCorePoolSize(Integer.parseInt(property)); |
45 ((ThreadPoolExecutor)threadPool).setCorePoolSize(Integer.parseInt(property)); |
45 ((ThreadPoolExecutor)threadPool).setMaximumPoolSize(Integer.parseInt(property)); |
46 ((ThreadPoolExecutor)threadPool).setMaximumPoolSize(Integer.parseInt(property)); |
46 } |
47 } |
47 TaskRunnable taskRunnable = new TaskRunnable(); |
48 TaskRunnable taskRunnable = new TaskRunnable(); |
48 threadPool.submit(taskRunnable); |
49 threadPool.submit(taskRunnable); |
49 try { |
50 try { |
50 synchronized (semaphore) { |
51 synchronized (semaphore) { |
51 while (!taskRunnable.isFinished()) |
52 while (!taskRunnable.isFinished()) { |
52 semaphore.wait(); |
53 semaphore.wait(); |
|
54 } |
53 } |
55 } |
54 } catch (InterruptedException e) { e.printStackTrace(); } |
56 } catch (InterruptedException e) { e.printStackTrace(); } |
55 |
57 |
56 Throwable exception = taskRunnable.getException(); |
58 Throwable exception = taskRunnable.getException(); |
57 if (exception != null) |
59 if (exception != null) |
58 { |
60 { |
59 if (exception instanceof BuildException) |
61 if (exception instanceof BuildException) { |
60 throw (BuildException)exception; |
62 throw (BuildException)exception; |
61 else |
63 } else { |
62 exception.printStackTrace(); |
64 exception.printStackTrace(); |
|
65 } |
63 } |
66 } |
64 } |
67 } |
65 |
68 |
66 private class TaskRunnable implements Runnable { |
69 private class TaskRunnable implements Runnable { |
67 private boolean finished; |
70 private boolean finished; |