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
Similar Messages
-
Hi,
I amhaving problem with a thread pooling my code once allocates a thread to a user then never is able to find that it is idle. the code is some what like this.
public class foo extends Thread{
pubblic void setPrimeData(Hashtable data){
//sets the primary data
run()
this.isrunning = true;
//does something
this.isrunning= false;
}You cannot restart a Thread. Once it has run, it cannot be reused. If you want to hand new tasks to threads in a pool, device some means by which you can hand a running (started) thread a new Runnable to execute in its run() method.
Chuck -
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 -
Increasing size of the Server Thread Pool
Whilst running a clustered JMS application with 3 servers, I get the
following error from the client:
<JavaSocketMuxer> <There are: '3' active sockets, but the maximum number of
socket readers allowed by the configuration is: '2', you may want to alter
your configuration.>
The error occurs with both Native IO and Java IO.
There are two parameters that appear to affect the number of socket readers,
a parameter called:
"ThreadPoolPercentSocketReaders"
and
"ThreadPoolSize"
The first parameter is well documented, and is in the DTD for "config.xml".
The second parameter is not. The only reference in the documentation I have
found so far is in the FAQs document, where "ThreadPoolSize" is a parameter
of the <Server> element (as you'd expect). However, when I tried to set this
manually in "config.xml", the parameter was removed after a server restart.
Anyone know about the error and/or the server "ThreadPoolSize" parameter?
Thanks
AlanThis is a client-side configuration issue - you can configure it
(I'm not sure about exact syntax) like this (when starting the client):
java -Dweblogic.ThreadPoolSize=10 -Dweblogic.ThreadPoolPercentSocketReaders=60 ... your.client ...
Alan Magrath <[email protected]> wrote:
Whilst running a clustered JMS application with 3 servers, I get the
following error from the client:
<JavaSocketMuxer> <There are: '3' active sockets, but the maximum number of
socket readers allowed by the configuration is: '2', you may want to alter
your configuration.>
The error occurs with both Native IO and Java IO.
There are two parameters that appear to affect the number of socket readers,
a parameter called:
"ThreadPoolPercentSocketReaders"
and
"ThreadPoolSize"
The first parameter is well documented, and is in the DTD for "config.xml".
The second parameter is not. The only reference in the documentation I have
found so far is in the FAQs document, where "ThreadPoolSize" is a parameter
of the <Server> element (as you'd expect). However, when I tried to set this
manually in "config.xml", the parameter was removed after a server restart.
Anyone know about the error and/or the server "ThreadPoolSize" parameter?
Thanks
Alan--
Dimitri -
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. -
Problem while reading XML file from Aplication server(Al11)
Hi Experts
I am facing a problem while reading XML file from Aplication server using open data set.
OPEN DATASET v_dsn IN BINARY MODE FOR INPUT.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ DATASET v_dsn INTO v_rec.
WHILE sy-subrc <> 0.
ENDWHILE.
CLOSE DATASET v_dsn.
The XML file contains the details from an IDOC number , the expected output is XML file giving all the segments details in a single page and send the user in lotus note as an attachment, But in the present output after opening the attachment i am getting a single XML file which contains most of the segments ,but in the bottom part it is giving the below error .
- <E1EDT13 SEGMENT="1">
<QUALF>001</QUALF>
<NTANF>20110803</NTANF>
<NTANZ>080000</NTANZ>
<NTEND>20110803<The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource 'file:///C:/TEMP/notesD52F4D/SHPORD_0080005842.xml'.
/SPAN></NTEND>
<NTENZ>000000</NTENZ>
for all the xml its giving the error in bottom part , but once we open the source code and if we saved in system without changing anything the file giving the xml file without any error in that .
could any one can help to solve this issue .Hi Oliver
Thanx for your reply.
see the latest output
- <E1EDT13 SEGMENT="1">
<QUALF>003</QUALF>
<NTANF>20110803</NTANF>
<NTANZ>080000</NTANZ>
<NTEND>20110803</NTEND>
<NTENZ>000000</NTENZ>
<ISDD>00000000</ISDD>
<ISDZ>000000</ISDZ>
<IEDD>00000000</IEDD>
<IEDZ>000000</IEDZ>
</E1EDT13>
- <E1EDT13 SEGMENT="1">
<QUALF>001</QUALF>
<NTANF>20110803</NTANF>
<NTANZ>080000</NTANZ>
<NTEND>20110803<The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource 'file:///C:/TEMP/notesD52F4D/~1922011.xml'.
/SPAN></NTEND>
<NTENZ>000000</NTENZ>
E1EDT13 with QUALF>003 and <E1EDT13 SEGMENT="1">
with <QUALF>001 having almost same segment data . but E1EDT13 with QUALF>003 is populating all segment data
properly ,but E1EDT13 with QUALF>001 is giving in between. -
When using a thread pool executor (java.util.concurrent.ThreadPoolExecutor) to limit the number of threads executing at a time, the number of threads running still exceeds the limit number.
This is the code:
private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 3, 20, TimeUnit.SECONDS, new LinkedBlockingQueue());
The number of tasks in my program are 4, so i always have 4 threads running, although i limited it to 3.
Can anyone help me with this problem? Or can u propose another solution to limit the number of running threads? By the way, i also tried using a newFixedThreadPool() and got the same problem.
Thx.The number of tasks in my program are 4, so i always
have 4 threads running, although i limited it to 3.How do you know that there are 4 threads running? If you're generating a JVM thread dump, you're going to see threads that are used internally by the JVM.
Here's a simple program that creates a fixed-size threadpool and runs jobs. It limits the number of concurrent threads to 3. Compare it to what you're doing, I'm sure that you'll find something different. Also, verify that you're not creating threads somewhere else in your program; all of the ThreadPoolExecutor threads will have names of the form "pool-X-thread-Y"
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
public class ThreadPoolTest {
public static void main(String[] args) {
ExecutorService pool = Executors.newFixedThreadPool(3);
for (int ii = 0 ; ii < 10 ; ii++) {
pool.execute(new MyRunnable());
pool.shutdown();
private static class MyRunnable implements Runnable {
public void run() {
log("running");
try {
Thread.sleep(1000L);
catch (InterruptedException e) {
log("interrupted");
private void log(String msg) {
System.err.println(
msg + " on " + Thread.currentThread().getName()
+ " at " + System.currentTimeMillis());
} -
Java Server Threading Problems
Cross-posted at: http://www.java-forums.org/networking/41574-server-threading-confusion.html with no answers as of this edit.
I'm very new to networking in java, and it's been a few months since I last did any major programming. I decided to try out networking, and I'm beginning to get a feel for it, but I've jumped in to trying to make a server for a multiplayer game, and I've gotten a bit stuck about how to do it, specifically on how to use threads to take care of my clients, and still be able to keep track of the threads so I can have the server send out info to them about where characters are, when the threads should close because someone wants to log out, etc.
If anyone could help me out that would be awesome :D
Here's some code:
import java.net.*;
import java.io.*;
public class GameThread extends Thread // this is the actual thread class I made
public Socket socket;
public DataInputStream in;
public DataOutputStream out; // a socket and two I/O streams for sending ints
public GameThread(Socket socket) // typical constructor for getting socket
try
this.socket = socket;
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
catch(Exception e)
e.printStackTrace();
public Socket getSocket() // I don't believe this is ever used. Ignore it.
return socket;
public void print() // Used to make sure the thread is active/knows about the socket
System.out.println("GameThread says: " + socket);
public void run()
while(true)
}Here's the class I use to manage the threads, or, at least, where I attempt to do so.
import java.io.*;
import java.util.ArrayList;
import java.net.*;
public class Threader
public ArrayList clients;
public ArrayList<GameThread> threads; // GameThread is the thread class above
public Threader()
threads = new ArrayList<GameThread>(); //constructor for this arraylist
public void updateClientCount(ArrayList<Socket> clients) // this method works
this.clients = clients; // it's not the problem.
public void openThreads() //Here's probably where problems begin
if(clients.size() > threads.size()) // this is to make the threads arraylist
int f = clients.size()-threads.size();//equal length compared to clients arraylist
while(f > 1)
threads.add(null);
f--;
if(clients.size() < threads.size()) //same as above, just if threads is bigger
threads.subList(clients.size(),(threads.size()-1)).clear();
for(int h=0;h<clients.size();h++) //Here: for each client spot
if(threads.get(h) == null) //Threads is tested in that spot to see if there's
{ // A thread there
GameThread gt = new GameThread((Socket)clients.get(h));
threads.add(gt); //and if there isn't then it makes one
gt.start(); // and starts it, but I guess this isn't happening as I want
} // it to because in the method below none of the GameThreads print socket info
public void print() //used to make sure the Threader/GameThread(s) is getting the info
for(int y = 0;y<clients.size();y++)
System.out.println("Threader says: " + clients.get(y));
for(int x = 0;x<threads.size();x++)
threads.get(x).print();
}If anyone could help me find what is going on, or maybe (probably) I'm going about making a server wrong (I have another class with a serversocket and all, but I don't believe there are any bugs in it so it isn't included in here), so if I could get help that would be awesome.
Thanks guys!
Edited by: 848780 on Mar 30, 2011 8:55 PM
Edited by: 848780 on Mar 30, 2011 11:55 PMYour thread management is back to front. All you need is a new thread per client, started every time you accept a new Socket. When you do that, if you want to manage them, enter the new thread into a collection, and when it exits remove it. But you normally don't need to keep track of client threads. You may want to keep track of client Sockets, in which case you should maintain a collection of Sockets on the same basis.
-
I want to make a thread pool to handle UDP package request
so I set tow int variable :
norsize;
maxsize;
the norsize is normal amount threads when Server boot they will be creat;
the maxsize is when the quest is large and the norsize threads are not enough,The
Thead pool can increase to the amount
but how reduce the Thread pool amount when it reach the maxsize????That was funy (the Duke Dollars part) :)
Ok. This time with some code.
We have a class that manages work. This work is made up of Runnable objects and the threads that run it. Let's go with sample code instead of english, just remenber that I wrote this code directly to the post text area and didn't event compile it, although it should work.
publi class WorkQueue {
private LinkedList m_listRunnable;
private int m_nMinThread;
private int m_nMaxThread;
private int m_nTimeOut;
private int m_nNumThread;
private int m_nNumThreadWaiting;
public WorkQueue(int minThread, int maxThread, int timeOut) {
m_listRunnable = new LinkedList();
m_nMinThread = minThread;
m_nMaxThread = maxThread;
m_nTimeOut = timeOut;
m_nNumThread = 0;
m_nNumThreadWaiting = 0;
init();
private void init() {
/* Start MinThread threads */
for (i = 0; i < m_nMinThread; i++) {
new WorkSlaveThread();
m_nNumThread++;
/* Inner class for the work thread */
private class WorkSlaveThread extends Thread {
public WorkSlaveThread() {
public void run() {
/* Work unless no work is returned, then it should stop */
for (Runnable work = getNextWork(); work != null; work = getNextWork()) {
try {
work.run();
} catch (Throwable ex) {
/* Log the error */
ex.printStackTrace();
threadStopping();
private void threadStopping() {
synchronized (this) {
m_nNumThread--;
private Runnable getNextWork() {
Runnable work;
long starttime = System.currentTimeMillis();
long currenttime = starttime;
long timeOut = m_nTimeOut * 1000; // Assume the time on in the constructor is in seconds
synchronized (m_listRunnable) {
/* Until there is work and the time out hasn't exceed */
/* (time out ignored if the minimum umber of threads is reached) */
while ((m_listRunnable.size() == 0) && ((timeOut > (currenttime - starttime)) || (m_nThreads == m_nMinThreads))) {
try {
m_nNumThreadWaiting++;
m_listRunnable.wait(m_nTimeOut * 1000);
} catch (Exception ex) {
/* Exception are launched if the VM is going down */
return null;
} finally {
m_nNumThreadWaiting--;
currenttime = System.currentTimeMillis();
if (m_listRunnable.size () == 0) {
/* Stop threads procedure */
return null; // Null will stop the thread
} else {
work = (Runnable)m_listRunnable.remove(0);
return work;
public void addWork(Runnable work) {
synchronized (m_listRunnable) {
m_listRunnable.add(work);
/* Start threads if necessary */
if ((m_nNumThreadWaiting == 0) && (m_nNumThread < m_nMaxthread)) {
new WorkSlaveThread();
synchronized (this) {
m_nNumThread++;
/* Signal a waiting thread */
m_listRunnable.notify();
}Well, this about does it! I didn't compile this, nor this is the code I use internally (internally I have shutdown procedures to ensure all work is down and other things), but it should do all the things a mention previously (I don't think I forgot any thing).
Hope this helps,
Nuno -
The problem in the thread pool implemented by myself
Hello, I need to a thread pool in J2ME CDC 1.0 + FP 1.0, so I implemented a simple one by myself that also meets my own requirement.
Here is the main idea:
The thread pool creates a fixed number of threads in advance. When a task comes, it is put in the waiting list. All threads tries to get the tasks from the waiting list. If no task exists, the threads wait until someone wakes them up.
Here are the requirements from myself:
1. when a task has finished its work in one execution, it is put in the waiting list for the next run.
2. the task can control the delay between when the task owner tries to put it in the waiting list and when the task is actually put in the waiting list. I need this function because sometimes I don't want the tasks to run too often and want to save some CPU usage.
In my program, I creates two thread pools. In one pool, every task don't use the delay, and the thread pool works very well. The other pool has the tasks that use the delay, and sometimes, as I can see from the printed information, there are many tasks in the waiting list but 0 or 1 thread executes tasks. It seems that the waiting threads cannot wake up when new tasks comes.
I suspect the code in addTask(), but cannot find the reason why it fails. Could anyone please help me find out the bug in my code? I put the code of thread pool below
Thank you in advance
Zheng Da
ThreadPool.java
package j2me.concurrent;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import alvis.general.Util;
public class ThreadPool {
private int maxQueueSize;
private boolean running = true;
private Thread[] threads;
private LinkedList tasks = new LinkedList();
private Timer timer = new Timer(true);
private AtomicInteger usingThreads = new AtomicInteger(0);
private synchronized boolean isRunning() {
return running;
private synchronized void stopRunning() {
running = false;
private synchronized PoolTask getTask() {
while (tasks.isEmpty() && isRunning()) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
if (tasks.isEmpty())
return null;
// Util.log.info(Thread.currentThread().getName() +
// " gets a task, left tasks: " + tasks.size());
return (PoolTask) tasks.removeFirst();
private synchronized void addTaskNoDelay(PoolTask task) {
tasks.addLast(task);
notifyAll();
private synchronized void addTask(final PoolTask task) {
long delay = task.delay();
if (delay == 0) {
addTaskNoDelay(task);
} else {
timer.schedule(new TimerTask() {
public void run() {
addTaskNoDelay(task);
}, delay);
private synchronized int numTasks() {
return tasks.size();
private class PoolThread extends Thread {
public void run() {
Util.poolThreads.inc();
while (isRunning()) {
PoolTask task = getTask();
if (task == null) {
Util.poolThreads.dec();
return;
usingThreads.inc();
long currentTime = System.currentTimeMillis();
task.run();
long elapsedTime = System.currentTimeMillis() - currentTime;
if (elapsedTime > 100)
System.err.println(task.toString() + " takes " + ((double) elapsedTime)/1000 + "s");
usingThreads.dec();
if (!task.finish()) {
addTask(task);
Util.poolThreads.dec();
public ThreadPool(int size, int taskQueueSize) {
maxQueueSize = taskQueueSize;
threads = new Thread[size];
for (int i = 0; i < threads.length; i++) {
threads[i] = new PoolThread();
threads.start();
public synchronized boolean executor(PoolTask task) {
if (!isRunning()) {
return false;
Util.log.info("Thread Pool gets " + task + ", there are "
+ numTasks() + " waiting tasks");
if (numTasks() >= maxQueueSize) {
return false;
addTask(task);
return true;
public synchronized void destroy() {
stopRunning();
timer.cancel();
// TODO: I am not sure it can wake up all threads and destroy them.
this.notifyAll();
public synchronized void printSnapshot() {
System.err.println("using threads: " + usingThreads + ", remaining tasks: " + tasks.size());
PoolTask.javapackage j2me.concurrent;
public interface PoolTask extends Runnable {
* It shows if the task has already finished.
* If it isn't, the task will be put in the thread pool for the next execution.
* @return
boolean finish();
* It shows the delay in milliseconds that the task is put in the thread pool.
* @return
long delay();are receiving/sends tasks packets time consuming operation in your case or not? if it is not you do not need to use thread pools at all. you can create a queue like in your code through the linked list and dispatch this queue periodically with minimum monitor usage. try this.
import java.util.LinkedList;
public class PacketDispatcher extends Thread {
LinkedList list = new LinkedList();
public PacketDispatcher (String name) {
super(name);
public void putTask(Task task) {
synchronized (list) {
list
.add(task);
list.notify();
public void run() {
while (true/* your condition */) {
Task task = null;
synchronized (list) {
while (list.isEmpty())
try {
list.wait();
} catch (InterruptedException e) {
e.printStackTrace();
task = (Task)list
.poll();
if (task == null) {
try {
Thread
.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
continue;
task
.run();
if (!task.isFinished()) {
putTask(task);
Thread
.yield();
public static void main(String[] args) {
// just for test
try {
Thread.sleep (10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
PacketDispatcher dispatcher = new PacketDispatcher("Packet Dispatcher");
Task task = new Task();
dispatcher.putTask(task);
dispatcher.start();
try {
Thread.sleep (10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Task task2 = new Task();
dispatcher.putTask(task2);
class Task {
long result = 0;
public boolean isFinished () {
if (getResult() >= 10000000) {
return true;
return false;
public void run() {
for (int i = 0; i < 1000; i++) {
result += i;
public long getResult () {
return result;
} -
I'm running CF 9.0.1 on Ubuntu on an "Medium" Amazon EC2 instance. CF has been crashing intermittently (several times per day). At such times, running top gets me this (or something similar):
PID
USER
PR
NI
VIRT
RES
SHR
S
%CPU
%MEM
TIME+COMMAND
15855
wwwrun
20
0
1762m
730m
20m
S
99.3
19.4
13:22.96 coldfusion9
So, it's obviously consuming most of the server resources. The following error has been showing up in my cfserver.log in the leadup to each crash:
java.lang.RuntimeException: Request timed out waiting for an available thread to run. You may want to consider increasing the number of active threads in the thread pool.
If I run /opt/coldfusion9/bin/coldfusion status, I get:
Pg/Sec DB/Sec CP/Sec Reqs Reqs Reqs AvgQ AvgReq AvgDB Bytes Bytes
Now Hi Now Hi Now Hi Q'ed Run'g TO'ed Time Time Time In/Sec Out/Sec
0 0 0 0 -1 -1 150 25 0 0 -1352560 0 0
In the administrator, under Server Settings > Request Tuning, the setting for Maximum number of simultaneous Template requests is 25. So this makes sense so far. I could just increase the thread pool to cover these sort of load spikes. I could make it 200. (Which I did just now as a test.)
However, there's also this file /opt/coldfusion9/runtime/servers/coldfusion/SERVER-INF/jrun.xml. And some of the settings in there appear to conflict. For example, it reads:
<service class="jrunx.scheduler.SchedulerService" name="SchedulerService">
<attribute name="bindToJNDI">true</attribute>
<attribute name="activeHandlerThreads">25</attribute>
<attribute name="maxHandlerThreads">1000</attribute>
<attribute name="minHandlerThreads">20</attribute>
<attribute name="threadWaitTimeout">180</attribute>
<attribute name="timeout">600</attribute>
</service>
Which a) has fewer active threads (what does this mean?), and b) has a max threads that exceed the simultaneous request limit set in the admin. So, I'm not sure. Are these independent configs that need to be made to match manually? Or is the jrun.xml file supposed to be written by the CF Admin when changes are made there? Hmm. But maybe this is different because presumably the CF Scheduler should only use a subset of all available threads, right...so we'd always have some threads for real live users. We also have this in there:
<service class="jrun.servlet.http.WebService" name="WebService">
<attribute name="port">8500</attribute>
<attribute name="interface">*</attribute>
<attribute name="deactivated">true</attribute>
<attribute name="activeHandlerThreads">200</attribute>
<attribute name="minHandlerThreads">1</attribute>
<attribute name="maxHandlerThreads">1000</attribute>
<attribute name="mapCheck">0</attribute>
<attribute name="threadWaitTimeout">300</attribute>
<attribute name="backlog">500</attribute>
<attribute name="timeout">300</attribute>
</service>
This appears to have changed when I changed the CF Admin setting...maybe...but it's the activeHandlerThreads that matches my new maximum simulataneous requests setting...rather than the maxHandlerThreads, which again exceeds it. Finally, we have this:
<service class="jrun.servlet.jrpp.JRunProxyService" name="ProxyService">
<attribute name="activeHandlerThreads">200</attribute>
<attribute name="minHandlerThreads">1</attribute>
<attribute name="maxHandlerThreads">1000</attribute>
<attribute name="mapCheck">0</attribute>
<attribute name="threadWaitTimeout">300</attribute>
<attribute name="backlog">500</attribute>
<attribute name="deactivated">false</attribute>
<attribute name="interface">*</attribute>
<attribute name="port">51800</attribute>
<attribute name="timeout">300</attribute>
<attribute name="cacheRealPath">true</attribute>
</service>
So, I'm not certain which (if any) of these I should change and what exactly the relationship is between maximum requests and maximum threads. Also, since several of these list the maxHandlerThreads as 1000, I'm wondering if I should just set the maximum simultaneous requests to 1000. There must be some upper limit that depends on available server resources...but I'm not sure what it is and I don't really want to play around with it since it's a production environment.
I'm not sure if it pertains to this issue at all, but when I run a ps aux | grep coldfusion I get the following:
wwwrun 15853 0.0 0.0 8704 760 pts/1
S
20:22 0:00 /opt/coldfusion9/runtime/bin/coldfusion9 -jar jrun.jar -autorestart -start coldfusion
wwwrun 15855 5.4 18.2 1678552 701932 pts/1
Sl
20:22 1:38 /opt/coldfusion9/runtime/bin/coldfusion9 -jar jrun.jar -start coldfusion
There are always these two and never more than these two processes. So there does not appear to be a one-to-one relationship between processes and threads. I recall from an MX 6.1 install I maintained for many years that additional CF processes were visible in the process list. It seemed to me at the time like I had a process for each thread...so either I was wrong or something is quite different in version 9 since it's reporting 25 running requests and only showing these two processes. If a single process can have multiple threads in the background, then I'm given to wonder why I have two processes instead of one...just curious.
So, anyway, I've been experimenting while composing this post. As noted above I adjusted the maximum simulataneous requests up to 200. I was hoping this would solve my problem, but CF just crashed again (rather it slogged down and requests started timing out...so effectively "crashed"). This time, top looked similar (still consuming more than 99% of the CPU), but CF status looked different:
Pg/Sec DB/Sec CP/Sec Reqs Reqs Reqs AvgQ AvgReq AvgDB Bytes Bytes
Now Hi Now Hi Now Hi Q'ed Run'g TO'ed Time Time Time In/Sec Out/Sec
0 0 0 0 -1 -1 0 150 0 0 0 0 0 0
Obviously, since I'd increased the maximum simultaneous requests, it was allowing more requests to run simultaneously...but it was still maxing out the server resources.
Further experiments (after restarting CF) showed me that the server became unusably slogged after about 30-35 "Reqs Run'g", with all additional requests headed for an inevitible timeout:
Pg/Sec DB/Sec CP/Sec Reqs Reqs Reqs AvgQ AvgReq AvgDB Bytes Bytes
Now Hi Now Hi Now Hi Q'ed Run'g TO'ed Time Time Time In/Sec Out/Sec
0 0 0 0 -1 -1 0 33 0 0 -492 0 0 0
So, it's clear that increasing the maximum simultaneous requests has not helped. I guess what it comes down to is this: What is it having such a hard time with? Where are these spikes coming from? Bursts of traffic? On what pages? What requests are running at any given time? I guess I simply need more information to continue troubleshooting. If there are long-running requests, or other issues, I'm not seeing it in the logs (although I do have that option checked in the admin). I need to know which requests exactly are those responsible for these spikes. Any help would be much appreciated. Thanks.
~DayI really appreciate your help. However, I haven't been able to find the JRun Thread settings you describe above.
Under Request Tuning, I see:
Server Settings > Request Tuning
Request Limits
Maximum number of simultaneous Template requests
Restricts the number of simultaneously processed requests. Use this setting to increase overall system performance for heavy load applications. Requests beyond the specified limit are queued. On Standard Edition, you must restart ColdFusion to enable this setting.
Maximum number of simultaneous Flash Remoting requests
The number of Flash Remoting requests that can be processed concurrently.
Maximum number of simultaneous Web Service requests
The number of Web Service requests that can be processed concurrently.
Maximum number of simultaneous CFC function requests
The number of ColdFusion Component methods that can be processed concurrently via HTTP. This does not affect invocation of CFC methods from within CFML, only methods requested via an HTTP request.
Tag Limit Settings
Maximum number of simultaneous Report threads
The maximum number of ColdFusion reports that can be processed concurrently.
Maximum number of threads available for CFTHREAD
The maximum number of threads created by CFTHREAD that will be run concurrently. Threads created by CFTHREAD in excess of this are queued. On Standard Edition, the maximum limit is 10.
And under Java and JVM, I see:
Server Settings > Java and JVM
Java and JVM settings control the way ColdFusion starts the Java Virtual Machine when it starts. You can control settings like what classpaths are used and how memory is allocated as well as add custom command line arguments. Changing these settings requires restarting ColdFusion. If you enter an incorrect setting, ColdFusion may not restart properly.
Backups of the jvm.config file are created when you hit the submit button. You can use this backup to restore from a critical change.
Java Virtual Machine Path
Specifies the location of the Java Virtual Machine.
Minimum JVM Heap Size (MB) Maximum JVM Heap Size (MB)
The Memory Size settings determine the amount of memory that the JVM can use for programs and data.
ColdFusion Class Path
Specifies any additional class paths for the JVM, with multiple directories separated by commas.
JVM Arguments
-server -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Dcoldfusion.libPath={application.home}/../lib
Specifies any specific JVM initialization options, separated by spaces.
I did go take a look at FusionReactor and found it's not free (which would be fine, of course, if it would actually help). It looks like there's a fully functional demo, which is cool...but I've haven't been able to get it to install yet, so we'll see.
Thanks again!
~Day
(By the way, I've cross-posted this inquiry on StackOverflow. So if you're able to help me arrive at a solution you might want to answer there as well.) -
Pattern for Thread Pool?
Hi
i want to build a kind of download manager. The application should be able to handle some concurrent threads, each representing a download in progress.
I thought i might be more efficient to reuse a download thread after the download has ended as to create a new thread each time (like the connection object for db queries). Is this right? If yes, i thought to build a thread pool that serves a limited number of threaded download objects as requested (am I on the right way?).
Now, I have to basic problems: (a) is it right, that, if the run() method of a thread has ended, the whole thread gets destroved? if yes, how should i prevent the thread from being destroyed, so i can reuse it later on? Second (b) how would that pool mechnism look like, means, there must be some kind of vector where i put in and take out the threads.
As you see, these are basic "pool" technique questions. So, I thought, maybe there is a design pattern that would give me the basic mechanism, Does anyone know such a pattern?
Thanks for your help
joshI thought i might be more efficient to reuse a
download thread after the download has ended as to
create a new thread each time (like the connection
object for db queries). Is this right? If yes, iIt may be right, if creating new threads is wasting enough CPU cycles to justify the complication of a thread pool. Maybe for a high-load server it would be more efficient. You'll have to figure that out for your own specific application.
Another good use for thread pools is to avoid putting time-consuming operations in ActionListeners, etc. Instead you can have them pass the task off to a thread pool, keeping the GUI responsive.
Now, I have to basic problems: (a) is it right, that,
if the run() method of a thread has ended, the whole
thread gets destroved? if yes, how should i prevent
the thread from being destroyed, so i can reuse it
later on? Second (b) how would that pool mechnism look
like, means, there must be some kind of vector where i
put in and take out the threads. (a) You are right. Therefore, the worker threads should not exit their run() methods until interrupted. (b) Worker threads could check a job queue (containing Runnables, perhaps) and if there are none, they should wait() on some object. When another thread adds a new job to the queue, it should call notify() on the same object, thus waking up one of the worker threads to perform the task.
I wrote a thread pool once, just as an exercise. You will run into a number of problems and design issues (such as, what should the worker threads do when interrupted, exit immediately or clear the job queue and then exit?) If you have any more questions, ask in this thead.
Krum -
Cold Fusion in a generic thread pool and enabling JAVA don't mix
I've got Cold Fusion MX installed on a server running Sun One 6.1. I ran into a problem trying to enable JAVA (for servlet support) which I had previous disabled because I didn't use it.
Well, when I went to enable JAVA on the server last week, the service wouldn't restart and the error logs gave me no indication of the problem.
Through a tedious trial-and-error process I've found that having Cold Fusion running under a generic thread pool while trying to have JAVA (the j2ee plugin) running under Sun One simply doesn't work (for whatever reason).
Once I killed the pool, everything runs fine.
Does anyone happen to know why this is? I keep CFMX under its own thread pool because there are certain elements to CFMX that aren't wholly stable and can result in CFMX crashing. If it crashes, the process keeps accepting requests, but never processes them. I'd like to keep the native thread pool free to keep accepting non-CFMX requests even when CFMX crashes.
Thus the separate thread pool for CFMX.
But now I can't run CFMX in a separate thread pool with JAVA enabled.
Anyone have any insights into why this is?
ThanksTwo things. Firstly, it's better to use private static final Object classLock = new Object();because that saves you worrying about whether any other code synchronises on it. Secondly, if you do decide to go for the delegation route then java.lang.reflect.Proxy may be a good way forward.
-
Cannot add server to pool: OVMAPI_4004E, but hostname set to FQDN
It's very simillar problem like thread "Cannot Add Server to Pool: OVMAPI_4010E Attempt to send command: dispatch..", but setting
hostname with FQDN on Ora VM Manager and Ora VM Server, repairing all configuration files (using grep -R ...) and reboot OVM
server and OVMM didn't brought any effect...
Environment:
Oracle VM Server version 3.2.2
Build: 520
Oracle VM Manager:
Version: 3.2.2.520
Build: 20130218_520
Description:
I have discovered and setup an OVM Server. Then I tried to create a new pool "ikr-pool". When I tried to attach discovered server ("srv01-xx.cssz.cz"),
I got error attached bellow. After this actions svr01-xx stays incorrectly as "member of pool" in /etc/ovs-agent/db/server database, so I need on VM server
to stop ovs-agent, remove file /etc/ovs-agent/db/server, start ovs-agent again, and then re-take ownership on VM server again. Then srv01-xx stays
as "Unassigned server".
Regards
Vladislav Rames
<-------------------------------------------------------------------------------------------------------------Begin of error message--------------------------------------------------------------------------->
Job Construction Phase
Job ID: 1364477027337
begin()
Appended operation 'Server Join Server Pool' to object '31:33:37:35:32:32:5a:43:32:32:35:30:30:57:44:46 (srv01-xx.cssz.cz)'.
Appended operation 'Server Pool Construct' to object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'.
Appended operation 'Server Pool Virtual IP Configure' to object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'.
Appended operation 'Server Pool Member Update' to object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'.
Appended operation 'Server Cluster Configure' to object '31:33:37:35:32:32:5a:43:32:32:35:30:30:57:44:46 (srv01-xx.cssz.cz)'.
Appended operation 'Server Cluster Construct' to object '31:33:37:35:32:32:5a:43:32:32:35:30:30:57:44:46 (srv01-xx.cssz.cz)'.
commit()
Completed Step: COMMIT
Objects and Operations
Object (IN_USE): [Cluster] d0b83b23645cbca2
Object (IN_USE): [Server] 31:33:37:35:32:32:5a:43:32:32:35:30:30:57:44:46 (srv01-xx.cssz.cz)
Operation: Server Join Server Pool
Operation: Server Cluster Configure
Operation: Server Cluster Construct
Object (IN_USE): [ServerPool] 0004fb0000020000d0b83b23645cbca2 (ikr-pool)
Operation: Server Pool Construct
Operation: Server Pool Virtual IP Configure
Operation: Server Pool Member Update
Job Running Phase at 2013-03-28 14:23:47,337
Job Participants: []
Actioner
14:23:47,909: Starting operation 'Server Join Server Pool' on object '31:33:37:35:32:32:5a:43:32:32:35:30:30:57:44:46 (srv01-xx.cssz.cz)'
14:23:47,914: Completed operation 'Server Join Server Pool' with direction ==> LATER
14:23:47,920: Starting operation 'Server Pool Construct' on object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'
14:23:47,971: Completed operation 'Server Pool Construct' with direction ==> DONE
14:23:47,977: Starting operation 'Server Pool Virtual IP Configure' on object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'
14:23:53,221: Completed operation 'Server Pool Virtual IP Configure' with direction ==> DONE
14:23:53,232: Starting operation 'Server Pool Member Update' on object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'
Job Internal Error (Operation)com.oracle.ovm.mgr.api.exception.FailedOperationException: OVMAPI_4010E Attempt to send command: dispatch to server: srv01-xx.cssz.cz failed. OVMAPI_4004E Server Failed Command: dispatch https://?uname?:[email protected]:8899/api/3 set_pool_member_ip_list [10.20.11.11], Status: org.apache.xmlrpc.XmlRpcException: I/O error while communicating with HTTP server: Connection timed out [Thu Mar 28 14:36:30 CET 2013] [Thu Mar 28 14:36:30 CET 2013]
at com.oracle.ovm.mgr.action.ActionEngine.sendCommandToServer(ActionEngine.java:512)
at com.oracle.ovm.mgr.action.ActionEngine.sendDispatchedServerCommand(ActionEngine.java:449)
at com.oracle.ovm.mgr.action.ActionEngine.sendServerCommand(ActionEngine.java:383)
at com.oracle.ovm.mgr.action.ServerPoolAction.setServerPoolMembers(ServerPoolAction.java:138)
at com.oracle.ovm.mgr.op.virtual.ServerPoolMemberUpdate.updateMemberList(ServerPoolMemberUpdate.java:363)
at com.oracle.ovm.mgr.op.virtual.ServerPoolMemberUpdate.action(ServerPoolMemberUpdate.java:138)
at com.oracle.ovm.mgr.api.collectable.ManagedObjectDbImpl.executeCurrentJobOperationAction(ManagedObjectDbImpl.java:1156)
at com.oracle.odof.core.AbstractVessel.invokeMethod(AbstractVessel.java:356)
at com.oracle.odof.core.AbstractVessel.invokeMethod(AbstractVessel.java:333)
at com.oracle.odof.core.storage.Transaction.invokeMethod(Transaction.java:865)
at com.oracle.odof.core.Exchange.invokeMethod(Exchange.java:244)
at com.oracle.ovm.mgr.api.virtual.ServerPoolProxy.executeCurrentJobOperationAction(Unknown Source)
at com.oracle.ovm.mgr.api.job.JobEngine.operationActioner(JobEngine.java:230)
at com.oracle.ovm.mgr.api.job.JobEngine.operationActioner(JobEngine.java:264)
at com.oracle.ovm.mgr.api.job.JobEngine.operationActioner(JobEngine.java:264)
at com.oracle.ovm.mgr.api.job.JobEngine.objectActioner(JobEngine.java:322)
at com.oracle.ovm.mgr.api.job.InternalJobDbImpl.objectCommitter(InternalJobDbImpl.java:1340)
at com.oracle.odof.core.AbstractVessel.invokeMethod(AbstractVessel.java:356)
at com.oracle.odof.core.AbstractVessel.invokeMethod(AbstractVessel.java:333)
at com.oracle.odof.core.BasicWork.invokeMethod(BasicWork.java:106)
at com.oracle.odof.command.InvokeMethodCommand.process(InvokeMethodCommand.java:92)
at com.oracle.odof.core.BasicWork.processCommand(BasicWork.java:81)
at com.oracle.odof.core.TransactionManager.processCommand(TransactionManager.java:752)
at com.oracle.odof.core.WorkflowManager.processCommand(WorkflowManager.java:467)
at com.oracle.odof.core.WorkflowManager.processWork(WorkflowManager.java:525)
at com.oracle.odof.io.AbstractClient.run(AbstractClient.java:42)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.oracle.ovm.mgr.api.exception.IllegalOperationException: OVMAPI_4004E Server Failed Command: dispatch https://?uname?:[email protected]:8899/api/3 set_pool_member_ip_list [10.20.11.11], Status: org.apache.xmlrpc.XmlRpcException: I/O error while communicating with HTTP server: Connection timed out [Thu Mar 28 14:36:30 CET 2013]
at com.oracle.ovm.mgr.action.ActionEngine.sendAction(ActionEngine.java:803)
at com.oracle.ovm.mgr.action.ActionEngine.sendCommandToServer(ActionEngine.java:508)
... 34 more
FailedOperationCleanup
Starting failed operation 'Server Pool Member Update' cleanup on object 'ikr-pool'
Complete rollback operation 'Server Pool Member Update' cleanup on object 'ikr-pool'
Rollbacker
14:36:31,156: Starting rollbacker...
Executing rollback operation 'Server Pool Member Update' on object '0004fb0000020000d0b83b23645cbca2 (ikr-pool)'
<-------------------------------------------------------------------------------------------------------------End of error message----------------------------------------------------------------------------->Solved. Problem was the same like in thread "I/O error while communicating with HTTP server: Connection timed out" - it wasn't accessible IP connection between Ora VM Manager and Ora VM server IP alias for server pool. But there was very confusing message in errorlog: "dispatch https://?uname?:[email protected]:8899/api/3 set_pool_member_ip_list [10.20.11.11], Status: org.apache.xmlrpc.XmlRpcException: I/O error while communicating with HTTP server: Connection timed out [Thu Mar 28 14:36:30 CET 2013]". Noticed IP address was IP address for VM server, not for VM pool, which makes me quite angry.
Best Regards
Vladislav Rames -
100% thread pool/CPU usage prevent MII Applications from working
Hello to all,
our MII Applications were running on MII 11.5 (windowsserver 2003, with IIS) without any problems.
We migrated these MII Applications to SAP xMII Version 12.0 SP8, SAP NW 7.00 SP20, Java HotSpot(TM) 64-Bit Server VM (build 1.4.2_22-rev-b03, mixed mode).
Since then we faced several problems that prevent the MII Applications from working, e.g.
- 100% application thread pool usage rate
- 100% CPU usage
- awful lot of http connections
Several sap support calls didn't find the root cause.
Workaround: restart sap system weekly
Does anyone has any idea how to go on?
Thanks
SimoneHi Mike,
sap support told us to install this Java version.
Furthermore SAP Note 716604 says "do not use J2SE 5.0" and "Currently, we recommend 1.4.2_24 b06".
Any more ideas?
Regards,
Simone
Maybe you are looking for
-
I'm in Safari and the ribbon at the top is bright and I can do a search, but the remainder of the screen is highlighted and I can't move around in Safari or select a topic etc, it appears to be locked. Does anyone know how to fix?
-
How do I make a reference that I can assign data to? Or,how do I mime void*
OK, I'm trying to do something where a class has 20+ variables, and I want to make a small, quick, and easy programming interface for it. There will be an assignment function that takes an integer indicating one of the variables, and an object, and a
-
How to search a .csv file for data using its timestamp, then import to labview
Hi, I'm currently obtaining density, viscosity and temperature data from an instrument, adding a timestamp and writing it to a .csv file which I can view in Excel. This works fine (see attached code) but what I need to do now is to search that csv fi
-
MRP4 view exclude storage location & material provided by vendor/customer..
Hi Could anyone please tell me in MRP4 view for a material,where is the option so that i can exclude or include the storage location stock from MRP? and also in which T code i should indicate the material is provided by vendor/material provided by cu
-
Where is the discussion group for iPhone developers?
I have tried, but faild, to find any Apple hosted group for us new iPhone developers. Are we suppose to post our questions here? /BE