Fixed Size Thread Pool which infinitely serve task submitted to it
Hi,
I want to create a fixed size thread pool say of size 100 and i will submit around 200 task to it.
Now i want it to serve them infinitely i.e once all tasks are completed re-do them again and again.
public void start(Vector<String> addresses)
//Create a Runnable object of each address in "addresses"
Vector<FindAgentRunnable> runnables = new Vector<FindAgentRunnable>(1,1);
for (String address : addresses)
runnables.addElement(new FindAgentRunnable(address));
//Create a thread pool of size 100
ExecutorService pool = Executors.newFixedThreadPool(100);
//Here i added all the runnables to the thread pool
for(FindAgentRunnable runnable : runnables)
pool.submit(runnable);
pool.shutdown();
}Now i wants that this thread pool execute the task infinitely i.e once all the tasks are done then restart all the tasks again.
I have also tried to add then again and again but it throws a java.util.concurrent.RejectedExecutionException
public void start(Vector<String> addresses)
//Create a Runnable object of each address in "addresses"
Vector<FindAgentRunnable> runnables = new Vector<FindAgentRunnable>(1,1);
for (String address : addresses)
runnables.addElement(new FindAgentRunnable(address));
//Create a thread pool of size 100
ExecutorService pool = Executors.newFixedThreadPool(100);
for(;;)
for(FindAgentRunnable runnable : runnables)
pool.submit(runnable);
pool.shutdown();
try
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
catch (InterruptedException ex)
Logger.getLogger(AgentFinder.class.getName()).log(Level.SEVERE, null, ex);
}Can anybody help me to solve this problem?
Thnx in advance.
Ravi_Gupta wrote:
*@ kajbj*
so what should i do?
can you suggest me a solution?Consider this thread "closed". Continue to post in your other thread. I, and all others don't want to give answers that already have been given.
Similar Messages
-
Fixed size thread pool excepting more tasks then it should
Hello,
I have the following code in a simple program (code below)
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10, false);
ThreadPoolExecutor newPool = new ThreadPoolExecutor(1, 10, 20, TimeUnit.SECONDS, q);
for (int x = 0; x < 30; x++) {
newPool.execute(new threaded());
My understanding is that this should create a thread pool that will accept 10 tasks, once there have been 10 tasks submitted I should get RejectedExecutionException, however; I am seeing that when I execute the code the pool accepts 20 execute calls before throwing RejectedExecutionException. I am on Windows 7 using Java 1.6.0_21
Any thoughts on what I am doing incorrectly?
Thanks
import java.util.concurrent.*;
public class ThreadPoolTest {
public static class threaded implements Runnable {
@Override
public void run() {
System.out.println("In thread: " + Thread.currentThread().getId());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("Thread: " + Thread.currentThread().getId()
+ " interuptted");
System.out.println("Exiting thread: " + Thread.currentThread().getId());
private static int MAX = 10;
private Executor pool;
public ThreadPoolTest() {
super();
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(MAX/2, false);
ThreadPoolExecutor newPool = new ThreadPoolExecutor(1, MAX, 20, TimeUnit.SECONDS, q);
pool = newPool;
* @param args
public static void main(String[] args) {
ThreadPoolTest object = new ThreadPoolTest();
object.doThreads();
private void doThreads() {
int submitted = 0, rejected = 0;
for (int x = 0; x < MAX * 3; x++) {
try {
System.out.println(Integer.toString(x) + " submitting");
pool.execute(new threaded());
submitted++;
catch (RejectedExecutionException re) {
System.err.println("Submission " + x + " was rejected");
rejected++;
System.out.println("\n\nSubmitted: " + MAX*2);
System.out.println("Accepted: " + submitted);
System.out.println("Rejected: " + rejected);
}I don't know what is wrong because I tried this
public static void main(String args[]) {
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10, false);
ThreadPoolExecutor newPool = new ThreadPoolExecutor(1, 10, 20, TimeUnit.SECONDS, q);
for (int x = 0; x < 100; x++) {
System.err.println(x + ": " + q.size());
newPool.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(1000);
return null;
}and it printed
0: 0
1: 0
2: 1
3: 2
4: 3
5: 4
6: 5
7: 6
8: 7
9: 8
10: 9
11: 10
12: 10
13: 10
14: 10
15: 10
16: 10
17: 10
18: 10
19: 10
20: 10
Exception in thread "main" java.util.concurrent.RejectedExecutionException
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1768)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:92)
at Main.main(Main.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)Ihave Java 6 update 24 on Linux, but I don't believe this should make a difference. Can you try my code? -
How to correctly use a fixed size thread pool?
I am quite new to using concurrency in Java, so please forgive if this is a trivial question.
I would like to make use of something like pool=Executors.newFixedThreadPool(n) to automatically use a fixed number of threads to process pieces of work. I understand that I can asynchronously run some Runnable by one of the threads in the threadpool using pool.execute(someRunnable).
My problem is this: I have some fixed amount of N datastructures myDS (which are not reentrant or sharable) that get initialized at program start and which are needed by the runnables to do the work. So, what I really would like to do is that I not only reuse N threads but also N of these datastructures to do the work.
So, lets say I want to have 10 threads, then I would want to create 10 myDS objects once and for all. Each time some work comes in, I want that work to get processed by the next free thread, using the next free datastructure. What I was wondering is if there is something in the library that lets me do the resusing of threads AND datastructures as simply as just reusing a pool of threads. Ideally, each thread would get associated with one datastructure somehow.
Currently I use an approach where I create 10 Runnable worker objects, each with its own copy of myDS. Those worker objects get stored in an ArrayBlockingQueue of size 10. Each time some work comes in, I get the next Runner from the queue, pass it the piece of work and submit it to the thread pool.
The tricky part is how to get the worker object back into the Queue: currently I essentially do queue.put(this) at the very end of each Runnable's run method but I am not sure if that is safe or how to do it safely.
What are the standard patterns and library classes to use for solving this problem correctly?Thank you for that feedback!
There is one issue that worries me though and I obviously do not understand it enough: as I said I hand back the Runnable to the blocking queue at the end of the Runnable.run method using queue.put(this). This is done via a static method from the main class that creates the threads and runnable objects in a main method. Originally I tried to make that method for putting back the Runnable objects serialized but that inevitably always led to a deadlock or hang condition: the method for putting back the runnable was never actually run. So I ended up doing this without serializing the put action in any way and so far it seems to work ... but is this safe?
To reiterate: I have a static class that creates a thread pool object and a ArrayBlockingQueue queue object of runnable objects. In a loop I use queue.take() to get the next free runnable object, and pass this runnable to pool.execute. Inside the runnable, in method run, i use staticclass.putBack(this) which in turn does queue.put(therunnableigot). Can I trust that this queue.put operation, which can happen from several threads at the same time works without problem without serializing it explicitly? And why would making the staticclass.putBack method serialized cause a hang? I also tried to serialize using the queue object itself instead of the static class, by doing serialize(queue) { queue.put(therunnable) } but that also caused a hang. I have to admit that I do not understand at all why that hang occurred and if I need the serialization here or not. -
How can I use the same thread pool implementation for different tasks?
Dear java programmers,
I have written a class which submits Callable tasks to a thread pool while illustrating the progress of the overall procedure in a JFrame with a progress bar and text area. I want to use this class for several applications in which the process and consequently the Callable object varies. I simplified my code and looks like this:
threadPoolSize = 4;
String[] chainArray = predock.PrepareDockEnvironment();
int chainArrayLength = chainArray.length;
String score = "null";
ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
CompletionService<String> referee = new ExecutorCompletionService<String>(executor);
for (int i = 0; i < threadPoolSize - 1; i++) {
System.out.println("Submiting new thread for chain " + chainArray);
referee.submit(new Parser(chainArray[i]));
for (int chainIndex = threadPoolSize; chainIndex < chainArrayLength; chainIndex++) {
try {
System.out.println("Submiting new thread for chain " + chainArray[chainIndex]);
referee.submit(new Parser(chainArray[i]));
score = referee.poll(10, TimeUnit.MINUTES).get();
System.out.println("The next score is " + score);
executor.shutdown();
int index = chainArrayLength - threadPoolSize;
score = "null";
while (!executor.isTerminated()) {
score = referee.poll(10, TimeUnit.MINUTES).get();
System.out.println("The next score is " + score);
index++;
My question is how can I replace Parser object with something changeable, so that I can set it accordingly whenever I call this method to conduct a different task?
thanks,
TomOK lets's start from the beginning with more details. I have that class called ProgressGUI which opens a small window with 2 buttons ("start" and "stop"), a progress bar and a text area. It also implements a thread pool to conducts the analysis of multiple files.
My main GUI, which is much bigger that the latter, is in a class named GUI. There are 3 types of operations which implement the thread pool, each one encapsulated in a different class (SMAP, Dock, EP). The user can set the necessary parameters and when clicking on a button, opens the ProgressGUI window which depicts the progress of the respective operation at each time step.
The code I posted is taken from ProgressGui.class and at the moment, in order to conduct one of the supported operations, I replace "new Parser(chainArray)" with either "new SMAP(chainArray[i])", "new Dock(chainArray[i])", "new EP(chainArray[i])". It would be redundant to have exactly the same thread pool implementation (shown in my first post) written 3 different times, when the only thing that needs to be changed is "new Parser(chainArray[i])".
What I though at first was defining an abstract method named MainOperation and replace "new Parser(chainArray[i])" with:
new Callable() {
public void call() {
MainOperation();
});For instance when one wants to use SMAP.class, he would initialize MainOperation as:
public abstract String MainOperation(){
return new SMAP(chainArray));
That's the most reasonable explanation I can give, but apparently an abstract method cannot be called anywhere else in the abstract class (ProgressGUI.class in my case).
Firstly it should be Callable not Runnable.Can you explain why? You are just running a method and ignoring any result or exception. However, it makes little difference.ExecutorCompletionService takes Future objects as input, that's why it should be Callable and not Runnable. The returned value is a score (String).
Secondly how can I change that runMyNewMethod() on demand, can I do it by defining it as abstract?How do you want to determine which method to run?The user will click on the appropriate button and the GUI will initialize (perhaps implicitly) the body of the abstract method MainOperation accordingly. Don't worry about that, this is not the point.
Edited by: tevang2 on Dec 28, 2008 7:18 AM -
ScheduledThreadPoolExecutor core thread pool / keepalive/timing out threads
Hi,
I am using a ScheduledThreadPoolExecutor - java1.6 on Windows(currently).
I would like to minimise the number of threads in the pool running at any one time to around the number of threads required to run the number of tasks that are concurrently executing.
However, I don't seem to be able to get the thread pool to minimise the number of threads below the max threads in the constructor.
I want to do this mainly because I have a large delay queue and the performance of the pool seems to be better when the number of threads in the pool is minimised to roughly the number of threads required to service the concurrently executing tasks.
Any ideas?
Thanks,
Alex
ThreadFactory tf = new MyThreadFactory();
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(50,tf);
scheduler.setCorePoolSize(10);
//scheduler.setMaximumPoolSize(50);
scheduler.setKeepAliveTime(1, TimeUnit.NANOSECONDS);
scheduler.allowCoreThreadTimeOut(true);
scheduler.schedule(aTask, 10, TimeUnit.SECONDS);
...because of how a scheduledthreadpoolexecutor works, it doesn't really make sense to have a variable number of threads. since threads are only added when tasks are added to the pool (aka, when submit is called), once the core threads timed out they would never get replaced (e.g. you would eventually get down to 1 thread and never get anymore added). one way to achieve what you want would be to have a single threaded ScheduledThreadPoolExecutor, where the scheduled jobs do the real work in a separate, variable size thread pool (e.g. the scheduled tasks do not do anything but submit a task to the real work thread pool). this solution would work fine for "schedule at fixed rate" but not for "schedule with fixed delay". you would actually have to simulate the latter by scheduling a one-off task which resubmits itself to the scheduler each time it completes.
-
How do we know that a given task(implementing Callable) in a thread pool (ThreadPoolExecutor) is completed ?
I know that we can use the get( ) method of Future class... but for that the current thread has to wait until the Task given to the Thread pool completed.
But I want to know ..Is it possible to get (asynchronus)notification from Thread pool when one of the submitted task finish.What about using the isDone() method of Future or even get(timeout, TimeUnit.SECONDS).
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html -
Submit submit a large number of task to a thread pool (more than 10,000)
i want to submit a large number of task to a thread pool (more than 10,000).
Since a thread pool take runnable as input i have to create as many objects of Runnable as the number of task, but since the number of task is very large it causes the memory overflow and my application crashes.
Can you suggest me some way to overcome this problem?Ravi_Gupta wrote:
I have to serve them infinitely depending upon the choice of the user.
Take a look at my code (code of MyCustomRunnable is already posted)
public void start(Vector<String> addresses)
searching = true;What is this for? Is it a kind of comment?
>
Vector<MyCustomRunnable> runnables = new Vector<MyCustomRunnable>(1,1);
for (String address : addresses)
try
runnables.addElement(new MyCustomRunnable(address));
catch (IOException ex)
ex.printStackTrace();
}Why does MyCustomRunnable throw an IOException? Why is using up resources when it hasn't started. Why build this vector at all?
>
//ThreadPoolExecutor pool = new ThreadPoolExecutor(100,100,50000L,TimeUnit.MILLISECONDS,new LinkedBlockingQueue());
ExecutorService pool = Executors.newFixedThreadPool(100);You have 100 CPUs wow! I can only assume your operations are blocking on a Socket connection most of the time.
>
boolean interrupted = false;
Vector<Future<String>> futures = new Vector<Future<String>>(1,1);You don't save much by reusing your vector here.
for(int i=1; !interrupted; i++)You are looping here until the thread is interrupted, why are you doing this? Are you trying to generate loading on a remote server?
System.out.println("Cycle: " + i);
for(MyCustomRunnable runnable : runnables)Change the name of you Runnable as it clearly does much more than that. Typically a Runnable is executed once and does not create resources in its constructor nor have a cleanup method.
futures.addElement((Future<String>) pool.submit(runnable));Again, it unclear why you would use a vector rather than a list here.
>
for(Future<String> future : futures)
try
future.get();
catch (InterruptedException ex)
interrupted = true;If you want this to break the loop put the try/catch outside the loop.
ex.printStackTrace();
catch (ExecutionException ex)
ex.printStackTrace();If you are generating a load test you may want to record this kind of failure. e.g. count them.
futures.clear();
try
Thread.sleep(60000);Why do you sleep even if you have been interrupted? For better timing, you should sleep, before check if you futures have finished.
catch(InterruptedException e)
searching = false;again does nothing.
System.out.println("Thread pool terminated..................");
//return;remove this comment. its dangerous.
break;why do you have two way of breaking the loop. why not interrupted = true here.
searching = false;
System.out.println("Shut downing pool");
pool.shutdownNow();
try
for(MyCustomRunnable runnable : runnables)
runnable.close(); //release resources associated with it.
catch(IOException e)put the try/catch inside the loop. You may want to ignore the exception but if one fails, the rest of the resources won't get cleaned up.
The above code serve the task infinitely untill it is terminated by user.
i had created a large number of runnables and future objects and they remain in memory until
user terminates the operation might be the cause of the memory overflow.It could be the size of the resources each runnable holds. Have you tried increasing your maximum memory? e.g. -Xmx512m -
Combining the fixed and cached thread pools
Is there a way to 'combine' the behavior of cached and fixed thread pools ? I have a requirement where
- at startup, I need to execute a fixed number of short-lived tasks at the background
- after startup, on demand, I need to run one short-lived task at a time
If I use a fixed thread pool for my startup processing, it creates the fixed number of threads to process the tasks. But subsequently, those many threads are not required since my task submission is going to be one at a time. The remaining (n-1) threads therefore are really sitting idle & useless.
If I use a cached thread pool, then I cannot constrain the number of threads to run at startup (since it creates one for each task). Though it ends up taking those threads out after they are idle for a fixed period. But I'm worried that it might create many threads and possibly slowing down the startup ?
Is there a way to create a pool with a fixed number of threads but 'remove' a set of threads when they are idle ?
TIAv_bala wrote:
Thanks. The SynchronousQueue worked as expected. But I tried a LinkedBlockingQueue with size 1 hoping that would cause the second task submission to cause a new thread creation. It didn't. Instead it queues up the request (maybe the doc in ThreadPoolExecutor says that when it mentions "If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread"). I suppose if I were to try another it would create another thread ? (I was testing with only two tasks - the first one ended up creating a thread for the task and the next got queued since the queue capacity is 1)yes, the TPE will not start adding threads until the queue starts rejecting them. kind of odd in my opinion, but that's how it works.
Btw, that was an interesting idea to add a task that scale the core pool number down ! Currently it comes back down to just the one thread (my core pool size is one) after the idle timeout but your idea may give me a slightly better response since it will scale down the core pool size quicker....I suppose if there was a task submission before that idle time there maybe a performance hit (but I don't anticipate that in my case )?actually, that won't scale things down any faster. changing the core pool size will not ditch the other threads immediately, they will still stick around until they idle timeout. changing the core pool size allows you to not worry about the queue implementation (the first solution). you can set the initial core pool size to your "max" size on startup, then drop it down for the normal processing, all the while using a linkedblockingqueue of unlimited size. -
Hi,
I'm using WLS 6.1. The console has a setting for: JMS Thread Pool Size. I wanted to tune the number of threads used by JMS. I thought JMS asynch consumers would use threads in this pool however that doesn't seem to be the case (they all use the default execute threads and queues). Why is this setting available?
Note the BEA WebLogic JMS Performance Guide talks about tuning this value from version 6.1 up to 8.1 and states "On the server, incoming JMS related requests execute in the JMS execute queue/thread pool."
Thanks in advance for any responses,
MichDisregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.
-
Waiting all threads in a fixed thread pool
Hello, may I know how can I wait for all the threads in a fixed thread pool to be completed, without calling shutdownNow?
Executor pool = Executors.newFixedThreadPool(nThreads);
for(int i = 0; i < 10000; i++)
pool.execute(new StockHistoryRunnable(code));
// blah blah blah
// I would like to wait for all the 10000 task to be completed. There is a method named
// awaitTermination. However, in order to use the method, I have to first call shutdownNow.
// I do not want to do so, because I need to re-use the pool later.
//You could retrieve all the "Future" instances returned by calling "submit" on your Executor and then have a Thread sequentially wait for the completion of all these individual tasks by using "get". Of course, this will require some synchronization if it is possible that new tasks get queued while you are already waiting for the original ones to be completed. But this way you can easily find out when all tasks have completed.
-
Aplication server thread pool problem
I'm using sun app server 8.
After some time from starting (and using) the server, it stops responding to clients.
When I change the max number of threads on server the number of clients it can serve before hanging folows the change. So I guess that some threads are not recycled.
But, I can't get full thread dump to see what's happening.
Also I can't get any thread pool monitoring information through asadmin.
(I can see that EJB's are all removed successfuly)
Any suggestions.
Thanks in advance.First of all, thank you for helping me.
The client wasn't making problems, but server did. (I didn't said that I use the app. server on XP.)
For now I solved the problem by installing the new beta 2004Q4. It works fine now, it also has some thread monitoring in web console...
I was getting this, when I tried to monitor the thread-pool (it is set on HIGH):
asadmin> get -m server.thread-pools.thread-pool.thread-pool-1.*
No matches resulted from the wildcard expression.
CLI137 Command get failed.
If it means anything this is what I was getting when I do ctrl-break. (this thread dump stays the same even after server stops responding...)
Full thread dump Java HotSpot(TM) Client VM (1.4.2_04-b04 mixed mode):
"Thread-6" prio=5 tid=0x02edad08 nid=0xb40 runnable [331f000..331fd8c]
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:177)
at org.apache.commons.launcher.StreamConnector.run(StreamConnector.java:
115)
"Thread-5" prio=5 tid=0x02ebbb98 nid=0x8ac runnable [32df000..32dfd8c]
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:194)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:220)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
- locked <0x10089900> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at org.apache.commons.launcher.StreamConnector.run(StreamConnector.java:
115)
"Signal Dispatcher" daemon prio=10 tid=0x0093dc18 nid=0x930 waiting on condition
[0..0]
"Finalizer" daemon prio=9 tid=0x008a5c20 nid=0xbd0 in Object.wait() [2b5f000..2b
5fd8c]
at java.lang.Object.wait(Native Method)
- waiting on <0x10502a00> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
- locked <0x10502a00> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
"Reference Handler" daemon prio=10 tid=0x008a47f0 nid=0xb4 in Object.wait() [2b1
f000..2b1fd8c]
at java.lang.Object.wait(Native Method)
- waiting on <0x10502a68> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:429)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
- locked <0x10502a68> (a java.lang.ref.Reference$Lock)
"main" prio=5 tid=0x000362a0 nid=0xc38 runnable [7f000..7fc3c]
at java.lang.Win32Process.waitFor(Native Method)
at org.apache.commons.launcher.LaunchTask.execute(LaunchTask.java:705)
at org.apache.tools.ant.Task.perform(Task.java:341)
at org.apache.tools.ant.Target.execute(Target.java:309)
at org.apache.tools.ant.Target.performTasks(Target.java:336)
at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
at org.apache.commons.launcher.Launcher.start(Launcher.java:402)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at LauncherBootstrap.main(LauncherBootstrap.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.enterprise.admin.servermgmt.pe.PEInstancesManager.startInstan
ce(PEInstancesManager.java:115)
at com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager.startDomain(P
EDomainsManager.java:126)
at com.sun.enterprise.cli.commands.StartDomainCommand.runCommand(StartDo
mainCommand.java:59)
at com.sun.enterprise.cli.framework.CLIMain.invokeCommand(CLIMain.java:1
23)
at com.sun.enterprise.cli.framework.CLIMain.main(CLIMain.java:39)
"VM Thread" prio=5 tid=0x0093c698 nid=0x9b4 runnable
"VM Periodic Task Thread" prio=10 tid=0x00940438 nid=0xbd4 waiting on condition
"Suspend Checker Thread" prio=10 tid=0x0093d2b8 nid=0x2c0 runnable -
Hi,
I want to know if I set a system property "-Dweblogic.ThreadPoolSize", how will the
WLS get to know that the pool size has been changed, at run time?
E.g. I pass -Dweblogic.ThreadPoolSize=30 from the command-line. Then if I change
the pool size to 40 at runtime, is there any event that I can fire for the change
in property through APIs?
Thnx in advance.
Best Regards
Ali
Disregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.
-
What can be the maximum thread pool size used in java.
What happens if i put up a thread pool size in range of 10k or 20k.
how does affect system performance ???
Its quite urgent for me to know. Can someone help out ???
Regards
HrushiI'd say it depends on the machine you are running on, amount of memory and number of CPUs and such, not on Java itself. And with that many threads your implementation better be darn good in order not to be the bottleneck...
-
Thread pool rejecting threads when I don't think it should, ideas?
Hi,
I have a server application in which I only want a specific number of simultaneous requests. If the server gets more then this number it is suppose to close the connection (sends an HTTP 503 error to the client). To do this I used a fix thread pool. When I start the server and submit the max number of requests I get the expected behavior. However if I resubmit the request (within a small period of time, e.g. 1-15 seconds after the first one) I get very odd behavior in that some of the requests are rejected. For example if I set the max to 100 the first set of requests will work fine (100 requests, 100 responses). I then submit again and a small number will be rejected (I've seen it range from 1 to 15 rejected)....
I made a small app which kind of duplicates this behavior (see below). Basically when I see is that the first time submitting requests works fine but the second time I get a rejected one. As best as I can tell none should be rejected....
Here is the code, I welcome your thoughts or if you see something I am doing wrong here...
<pre>
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadPoolTest {
static AtomicInteger count = new AtomicInteger();
public static class threaded implements Runnable {
@Override
public void run() {
System.out.println("In thread: " + Thread.currentThread().getId());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println("Thread: " + Thread.currentThread().getId()
+ " interuptted");
System.out.println("Exiting run: " + Thread.currentThread().getId());
private static int maxThreads = 3;
private ThreadPoolExecutor pool;
public ThreadPoolTest() {
super();
pool = new java.util.concurrent.ThreadPoolExecutor(
1, maxThreads - 1, 60L, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(1));
public static void main(String[] args) throws InterruptedException {
ThreadPoolTest object = new ThreadPoolTest();
object.doThreads();
Thread.sleep(3000);
object.doThreads();
object.pool.shutdown();
try {
object.pool.awaitTermination(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
private void doThreads() {
int submitted = 0, rejected = 0;
int counter = count.getAndIncrement();
for (int x = 0; x < maxThreads ; x++) {
try {
System.out.println("Run #: " + counter + " submitting " + x);
pool.execute(new threaded());
submitted++;
catch (RejectedExecutionException re) {
System.err.println("\tRun #: " + counter + ", submission " + x
+ " was rejected");
System.err.println("\tQueue active: " + pool.getActiveCount());
System.err.println("\tQueue size: " + pool.getPoolSize());
rejected++;
System.out.println("\n\n\tRun #: " + counter);
System.out.println("\tSubmitted: " + (submitted + rejected));
System.out.println("\tAccepted: " + submitted);
System.out.println("\tRejected: " + rejected + "\n\n");
</pre>First thank you for taking the time to reply, I do appreciate it.
jtahlborn - The code provided here is a contrived example trying to emulate the bigger app as best as I could. The actual program doesn't have any sleeps, the sleep in the secondary thread is to simulate the program doing some work & replying to a request. The sleep in the primary thread is to simulate a small delay between 'requests' to the pool. I can make this 1 second and up to (at least) 5 seconds with the same results. Additionally I can take out the sleep in the secondary thread and still see the a rejection.
EJP - Yes I am aware of the TCP/IP queue, however; I don't see that as relevant to my question. The idea is not to prevent the connection but to respond to the client saying we can't process the request (send an "HTTP 503" error). So basically if we have, say, 100 threads running then the 101st, connection will get a 503 error and the connection will be closed.
Also my test platform - Windows 7 64bit running Java 1.6.0_24-b07 (32bit) on an Intel core i7.
It occurred to me that I did not show the output of the test program. As the output shows below, the first set of requests are all processed properly. The second set of requests is not. The pool should have 2 threads and 1 slot in the queue, so by the time the second "request" is made at least 2 of the requests from the first call should be done processing, so I could possibly understand run 1, submit #2 failing but not submit 1.
<pre>
Run #: 0 submitting 0
Run #: 0 submitting 1
Run #: 0 submitting 2
In thread: 8
In thread: 9
Exiting run: 8
Exiting run: 9
Run #: 0
Submitted: 3
Accepted: 3
Rejected: 0
In thread: 8
Exiting run: 8
Run #: 1 submitting 0
In thread: 9
Run #: 1 submitting 1
Run #: 1, submission 1 was rejected
Queue active: 1
Queue size: 2
Run #: 1 submitting 2
Run #: 1
Submitted: 3
Accepted: 2
Rejected: 1
In thread: 8
Exiting run: 9
Exiting run: 8
</pre> -
Thread pool throws reject exceptions even though the queue is not full
Hi. I am using org.springframework.scheduling.concurrent.ThreadPo olTaskExecutor which is based on java
java.util.concurrent.ThreadPoolExecutor
with a enviornment under load.
I see on some cases, that this thread pool throws tasks with reject exception
even though the queue size is 0.
According to the documentation, this thread pool should increase the pool size to core size and then wait untill all queue is full to create new threads.
this is not what happends. for some reason the queue is not filled but exceptions are thrown.
Any ideas why this can happen?This is the stack trace:
taskExecutorStats-1 2010-04-27 11:01:43,324 ERROR [com.expand.expandview.infrastructure.task_executor] TaskExecutorController: RejectedExecutionException exception in thread: 18790970, failed on thread pool: [email protected]544f07, to run logic: com.expand.expandview.infrastructure.logics.DispatchLogicsProviderLogic
org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@dd9007] did not accept task: com.expand.expandview.infrastructure.task_executor.TaskExecuterController$1@141f728; nested exception is java.util.concurrent.RejectedExecutionException
at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:305)
at com.expand.expandview.infrastructure.task_executor.TaskExecuterController.operate(TaskExecuterController.java:68)
at com.expand.expandview.infrastructure.proxies.DataProxy.callLogic(DataProxy.java:131)
at com.expand.expandview.infrastructure.proxies.DataProxy.operate(DataProxy.java:109)
at com.expand.expandview.infrastructure.logics.AbstractLogic.operate(AbstractLogic.java:455)
at com.expand.expandview.server.app.logics.stats.StatsPersisterSingleChunkLogic.persistSlots(StatsPersisterSingleChunkLogic.java:362)
at com.expand.expandview.server.app.logics.stats.StatsPersisterSingleChunkLogic.doLogic(StatsPersisterSingleChunkLogic.java:132)
at com.expand.expandview.infrastructure.logics.AbstractLogic.execute(AbstractLogic.java:98)
at com.expand.expandview.server.app.logics.ApplicationLogic.execute(ApplicationLogic.java:79)
at com.expand.expandview.infrastructure.task_executor.TaskExecuterControllerDirect.operate(TaskExecuterControllerDirect.java:33)
at com.expand.expandview.infrastructure.proxies.LogicProxy.service(LogicProxy.java:62)
at com.expand.expandview.infrastructure.logics.AbstractLogic.service(AbstractLogic.java:477)
at com.expand.expandview.server.app.logics.stats.StatsPersisterLogic.persist(StatsPersisterLogic.java:48)
at com.expand.expandview.server.app.logics.stats.StatsPersisterLogic.doLogic(StatsPersisterLogic.java:19)
at com.expand.expandview.infrastructure.logics.AbstractLogic.execute(AbstractLogic.java:98)
at com.expand.expandview.server.app.logics.ApplicationLogic.execute(ApplicationLogic.java:79)
at com.expand.expandview.infrastructure.task_executor.TaskExecuterController$1.run(TaskExecuterController.java:80)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.util.concurrent.RejectedExecutionException
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1760)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)
at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:302)
... 19 more
Maybe you are looking for
-
Mouse problems with Illustrator CS6 and Mountain Lion
The mouse in Illustrator selects and deselects as it moves over buttons and cells: 1. In Graph data the cells the mouse passes over go dark grey if not already selected, then deselect if they are selected. This makes it very difficult to use the data
-
Adjusting Exposure Compensation Settings Of 808 To...
Apart from the inaccurate white balance of the Pureview 808 in low light which appears to be a permanent feature of the phone(still waiting for confirmation from Nokia whether there will be a software update to correct this), it seems that the exposu
-
Windows 10 TP build 10041 seen as Windows 8.1 OS when imported to a Deployment Share
Hi all, I tried to import the Windows 10 TP build 10041 as operating system to a new deployment share created with MDT 2013 U1. I referenced the DVD iso image of Windows 10 Technical Preview 10041 and os type was recognized as Windows 8.1. Is there a
-
Running the NI 8253eventcount example on CVI 8.5
Dear friends, I am trying to run the NI 8253eventcount example ( http://zone.ni.com/devzone/cda/epd/p/id/512 ) on Windows XP system, provided with LABWindows /CVI 8.5 (evalution) and NI-DAQ 8.7.1 driver, and with NI PCI-6601 counter/timer device. The
-
Mpeg2-dvd outputs blank or black file
hi, When I render to mpeg2-dvd all I get is a blank file. It is 50Mb, but nothing shows up but black. what am I doing wrong?