Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #41 from ccorsi/master

Made some minor changes
  • Loading branch information...
commit 7d728819f4ae8ab3ba288ae10ee8ad69f01cdaa1 2 parents 075f7d1 + c032bd4
@laforge49 authored
View
43 src/main/java/org/agilewiki/jactor/concurrent/JAThreadManager.java
@@ -61,7 +61,7 @@
/**
* The worker threads.
*/
- final private ArrayList<Thread> threads = new ArrayList<Thread>();
+ private Thread threads[] = null;
/**
* Create a JAThreadManager
@@ -102,24 +102,23 @@ public void run() {
while (true) {
try {
taskRequest.acquire();
+ if (closing) return;
+ Runnable task = tasks.poll();
+ if (task != null)
+ try {
+ task.run();
+ } catch (Exception e) {
+ logException(false, "Exception thrown by a task's run method", e);
+ }
} catch (InterruptedException e) {
}
- if (closing) return;
- Runnable task = tasks.poll();
- if (task != null)
- try {
- task.run();
- } catch (Exception e) {
- logException(false, "Exception thrown by a task's run method", e);
- }
}
}
};
- int c = 0;
- while (c < threadCount) {
- c += 1;
+ threads = new Thread[this.threadCount];
+ for (int c = 0; c < threadCount; c++) {
Thread t = threadFactory.newThread(runnable);
- threads.add(t);
+ threads[c] = t;
t.start();
}
}
@@ -144,31 +143,23 @@ final public void process(Runnable task) {
@Override
final public void close() {
closing = true;
- int c = 0;
- while (c < threadCount) {
- c += 1;
- taskRequest.release();
- }
- c = 0;
+ taskRequest.release(threadCount);
Thread ct = Thread.currentThread();
- while (c < threadCount) {
- Thread t = threads.get(c);
+ for (Thread t : threads) {
if (ct != t) {
t.interrupt();
}
- c += 1;
}
- c = 0;
- while (c < threadCount) {
- Thread t = threads.get(c);
+ for (Thread t : threads) {
if (ct != t) {
try {
t.join();
} catch (InterruptedException e) {
}
}
- c += 1;
}
+ // Release the references to the thread array...
+ threads = null;
}
@Override
View
6 src/main/java/org/agilewiki/jactor/factory/_ActorFactory.java
@@ -34,7 +34,7 @@
/**
* The constructor used to create the actor.
*/
- private Constructor constructor;
+ private Constructor<JLPCActor> constructor;
/**
* Create an ActorFactory.
@@ -42,7 +42,7 @@
* @param actorType The actor type.
* @param constructor The constructor used to create the actor.
*/
- public _ActorFactory(String actorType, Constructor constructor) {
+ public _ActorFactory(String actorType, Constructor<JLPCActor> constructor) {
super(actorType);
this.constructor = constructor;
}
@@ -54,6 +54,6 @@ public _ActorFactory(String actorType, Constructor constructor) {
*/
protected JLPCActor instantiateActor()
throws Exception {
- return (JLPCActor) constructor.newInstance();
+ return constructor.newInstance();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.