Mod_jk thread problem

I have an apache server connected to tomcat via ajp13.
In the tomcats catalina.out file it keeps creating new ajp13 background threads up to its configured limit, and never releases them. When it reaches its limit, you get this error:-
Ajp13Connector[8009] No processor available, rejecting this connection
And the user sees a server 500 page.
What can I do to stop the threads just growing and growing ?
What could be causing this ?
Your help would be appreciated. I've trawled the net today with no luck.

We finally found the issue. In our environment we have a firewall between Application and DB servers. This firewall was originally set to kill idle connections between the servers after certain amount of time. Due to this setting, the firewall used to kill db connections in the pool, which were not used due to inactivity(but still open in the pool). Neither the app server nor the DB server aren't aware of this fact and they used try to use these dead connections and eventually bring the application down.
We can do several things to overcome this issue.
1. Set up a test query in the pool (like select * from dual)and set the pool to perform a test query at a time interval less than the firewall's connecion timeout setting. This will make the firewall think that the connection is active and it wont kill it. Many connection pools support such test query.
2. Donot use any such settings on the firewall for the specific port.
Though the following wasn't the case in our environment, we often found it useful to re-inspect all the application components that open and close the DB connections and make sure that they are properly closing connections under all circumstances(including the cases where the components might throw some exceptions).

Similar Messages

  • Sun Java System Web Server 6.1 SP3 service-j2ee threads problem

    Hi,
    Sorry my english.
    I'm an intermediate Java programmer and a newbie in
    the Sun's web servers world.
    I'm doing an evaluation of an web applicaction
    written in Java Servlets that is
    supposed to have a leaking threads problem. We use
    SunOS 5.9 (... sun4u sparc SUNW,UltraAX-i2) and
    JVM 1.5 Update 4 (the problem is presented too
    in SunOS 5.8 and JVM 1.4.2_04).
    We have seen, thanks to 'prstat' (PROCESS/NLWP) a
    increasing thread's growing in one of the process
    that correspond to our web server instance (I'm sure I'm
    looking the right process). I have checkout the source
    code and it seems like the app doesn't have threads
    problems. I have used the Netbeans Profiler and I see a
    high number of threads called service-j2ee-x that grows
    in congestion moments and never disappear.
    Anybody could help me with suggestions?
    Thank you very much.

    Elvin,
    Thankyou, yes I am unfamiliar with debugging Java apps. I got the web server Java stack trace and I have passed this on to the developer.
    The web server finally closes the socket connection after the total connections queued exceeds 4096.
    There are several hundred entries like this... waiting for monitor entry.. could be a deadlock somewhere?
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "service-j2ee-506" prio=5 tid=0x04b62a08 nid=0x17a waiting for monitor entry [dd74e000..dd74f770]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.util.JSDispenser.getConnResource(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting to lock <0xe979b2b0> (a com.verity.search.util.JSDispenser)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.getDoc(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.getDoc(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.docViewIntern(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.docView(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at au.com.relevance.viewDoc.PdfXmlServlet.performRequest(PdfXmlServlet.java:120)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at au.com.relevance.viewDoc.PdfXmlServlet.doGet(PdfXmlServlet.java:141)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at javax.servlet.http.HttpServlet.service(HttpServlet.java:787)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at javax.servlet.http.HttpServlet.service(HttpServlet.java:908)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:771)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:322)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:209)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:161)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[highlight]" daemon prio=5 tid=0x000f3530 nid=0x1e waiting on condition [e15ff000..e15ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[highlight]" daemon prio=5 tid=0x000f3328 nid=0x1d waiting on condition [e16ff000..e16ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[]" daemon prio=5 tid=0x000f2b08 nid=0x1c waiting on condition [e1b7f000..e1b7fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[]" daemon prio=5 tid=0x000f2900 nid=0x1b waiting on condition [e1c7f000..e1c7fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[sitesearch]" daemon prio=5 tid=0x000f1cd0 nid=0x1a waiting on condition [e23ff000..e23ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[sitesearch]" daemon prio=5 tid=0x000f1ac8 nid=0x19 waiting on condition [e24ff000..e24ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[search]" daemon prio=5 tid=0x000f0a88 nid=0x18 waiting on condition [e317f000..e317fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Signal Dispatcher" daemon prio=10 tid=0x000ef840 nid=0x12 waiting on condition [0..0]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Finalizer" daemon prio=8 tid=0x000ef638 nid=0x10 in Object.wait() [fa27f000..fa27fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting on <0xe917fb10> (a java.lang.ref.ReferenceQueue$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - locked <0xe917fb10> (a java.lang.ref.ReferenceQueue$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Reference Handler" daemon prio=10 tid=0x000ef430 nid=0xf in Object.wait() [fa37f000..fa37fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting on <0xe917fb78> (a java.lang.ref.Reference$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Object.java:429)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - locked <0xe917fb78> (a java.lang.ref.Reference$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "main" prio=5 tid=0x000ee3f0 nid=0x1 runnable [0..ffbff200]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "VM Thread" prio=5 tid=0x004ee328 nid=0xe runnable
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "VM Periodic Task Thread" prio=10 tid=0x004ee5d0 nid=0x16 waiting on condition
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Suspend Checker Thread" prio=10 tid=0x004ee548 nid=0x11 runnable
    [15/May/2006:22:15:10] failure ( 3196): HTTP3287: connection limit (4096) exceeded, closing socket

  • Cant syncronize! Threads problem

    Hello everybody,
    recently i posted a question(im new to threads) and it was asked immediately but now i have another
    type of problem.
    Please read here the initial post and the answer and please give me any ideas..
    Initial Post
    Hi everybody,i have this thread problem(i'm new to java and h
    ave no idea what exactly to do).
    Well,in my applet i have this action performed method
    that i imagine is in the event dispatch thread.
    This method calls as u see, two other methods of a class named CPU(.
    Note that fetch and execute are observed classes and my applet class
    is the observer.
    The problem is that during the execution of fetch() and execute(),
    inside these methods change some things and so they call notifyObservers(Object arg)
    passing to the applet the argument and so the applet updates some text components.
    But as you can immagine there is no time for the gui to update himself so i see nothing.
    So, my question is which of the methods need to be in a separate thread so to ensure
    visible results(component updating)?
    Perhaps,the update method needs to be invokedLater with SwingUtilities?
    Please give me an example code if possible.
    Here is the actionPerformed code(from the applet class) and the fetch method:
        void executeProgramButton_actionPerformed(ActionEvent e) {      
    int numInstr = this.machine.ram.segmentSize;       
    for (int i = 0; i < numInstr; i = i + 4) {           
    machine.cpu.fetch();           
    machine.cpu.execute();       
    /*The following method is in the CPU class
    fetch method:here the observedPC is the observable value
    that notifies the observer(the main applet)
    that does: pcTextField.setText(arg.toString());*/   
    public void fetchInstructionProgram() {       
    observedPC = Integer.toString(pc);       
    setChanged();       
    notifyObservers(observedPC);       
    instructions++;       
    instruction=readOperation(cache.instructionfetch,pc);       
    pc = pc + 4;    }
    Answer to initial post
    Author: stevejluke
    One way could be to put the content of the action performed method into a new thread, then use invokeLater in your Observers that cause GUI updates:
        void executeProgramButton_actionPerformed(ActionEvent e) {     
    new Thread()       {      
    public void run()        {         
    int numInstr = this.machine.ram.segmentSize;         
    for (int i = 0; i < numInstr; i = i + 4)           {           
    machine.cpu.fetch();           
    machine.cpu.execute();         
    }.start();    }
    // In your Observer    public void update(Observable o, Object arg)    {     
    SwingUtilities.invokeLater(new Runnable() {      
    public void run()        { 
    /* your GUI afecting code
    });[i]
    Or something like that.
    You might need to watch for synchronizing things
    He was right...GUI is responsive but the results...
    Well,let me describe the new problem.
    Here you cant see the method execute().
    The problem is a synchronization problem.
    Actually,what the two methods do is:fetch() updates the value of a long called instruction and execute() takes this value and do some things.Note also that the time the execute method needs to finish is not
    always the same.By that, i mean that it depends on the value of the instruction updated by fetch().
    By putting some System.outs before and after updating i realized that there are delays or sometimes
    i noticed that fetch() executes 2 times before execute() takes control.
    So,i created some synchronized private methods set and get to control access to these resources.
    Better but still not correct...
    What should i look?Where stays the answer?
    How to synchronize these two methods on these resources?
    Thank you in advance,
    Chris

    I think that your fetch and execute has a "Producer-Consumer Relationship"
    in such cases you can make the producer place the produced value in to a queue and consumer take the vlues from the queue
    In the producer thread it sleeps for a while and try again if the Queue is full
    In the Consumer thread it sleeps for a while if the Queue is empty and then try again
    Or you can do as follows
    In the Producer thread it waite() if the Queue is full
    In the Consumer thread it waite() if the queue is empty
    When ever Producer put a value in to the Queue it calls the notify on Consumer and when ever Consumer takes a value from Queue it calls the notify() on Producer
    you can even use notify all
    I think thiere is no built in Queue class in java so you will have to write one here is a example
    public class MyLongQueue{
                long data[];
                int head, tail;
                int size;
               public MyLongQueue(int size){
                    data = new long[size];
                    head = -1;
                    tail = -1;
                    this.size = 0;
                public synchronized boolean isFull(){
                    return (size==data.length);
                public synchronized boolean isEmpty(){
                    return (size==0);
                public synchronized boolean  insert(long l){
                    if (size==data.length) return false; //Queue is full cant add more data
                    tail = (tail + 1) % data.length;
                    data[tail] = l;
                     size++;
                    return true;
               public synchronized long remove(){
                   if (size==0) throw new ArrayIndexOutOfBoundsException();
                   size--;
                   head = (head + 1) % data.length;
                   return data[head];

  • JNI & thread problem

    Folks,
    I am using JNI to access WIA (Windows Image Acquisition) functionality under MS Windows XP. WIA consists of a bunch of COM interfaces. I have several native functions in a single dll, with a limited number of static variables stored in the dll between calls. This all works fine as long as long as the calls occur from the same java thread, but not if a new thread is created for some of the calls. I.e., this works:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    but this does not:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    (new Thread() {
    public void run() {               
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    }).start();
    Here, initializeWIA() and transferJPGNative() are the native methods. What happens in the second case is that transferJPGNative fails in one of the COM methods (not the first COM method it calls). The COM method returns an HRESULT indicating an error (509) which I can't find using any of the usual MS error look-up mechanisms. (Admittedly I am not the world's greatest Windows programmer...)
    Anyway, any suggestions would be much appreciated. I have found some issues regarding JNI and threads in this forum's archives, but none of them seem to apply to quite this situation.

    As a guess this is just a windows threading problem.
    And with COM you have to do things differently (I believe) if there is more than one thread. You might not even be allowed to do it with for that particular API.
    It could also be that you are initializing things more than once. Or you need to initialize twice (two handles.)
    At any rate you could always fix it by making the java code only allow calls for a single thread.

  • Thread problem in swings

    I have made an application in swings i have stored the class files in a system and call that class files by a batfile shortcut in two diff. pcs .and i am tring to get an value of a Jtextarea in an event When I tried to run this application at the same time from 2 diff PCS,with diff string input in text area It is giving me the same vlaue.
    Tell me Y it is so.and how can i rectify it
    javauser

    Very strange... what makes you think that this is a threading problem?

  • Urgent!!!!!!!HANDLER THREAD PROBLEM

    file name GetName.html
    <html>
    <body>
    <FORM METHOD = POST ACTION = "SaveName.jsp">
    what is your name?
    <INPUT TYPE = TEXT NAME=username SIZE= 20>
    <p><INPUT TYPE= SUBMIT>
    </FORM>
    </BODY>
    </HTML>
    file name SaveName.jsp
    <%
    String name = request.getParameter( "username" );
    session.setAttribute( "theName", name );
    %>
    <HTML>
    <BODY>
    Continue
    </BODY>
    </HTML>
    file name NextPage.jsp
    <html>
    <body>
    Hello, <%=session.getAttribute("theName") %>
    </body>
    </html>
    when I try to execute , SaveName.jsp is generating the following error message. what is the problem? I am using jswdk. please help. I have included tools.jar in classpath. what could be the problem?
    Unhandled error! You might want to consider having an error page to report such
    errors more gracefully
    com.sun.jsp.JspException: Compilation failed:Note: sun.tools.javac.Main has been
    deprecated.
    work\%3A8080%2Fexamples\SaveName_jsp_1.java:71: Method setAttribute(java.lang.St
    ring, java.lang.String) not found in interface javax.servlet.http.HttpSession.
    session.setAttribute( "theName", name );
    ^
    1 error, 1 warning
    at com.sun.jsp.compiler.Main.compile(Main.java:347)
    at com.sun.jsp.runtime.JspLoader.loadJSP(JspLoader.java:135)
    at com.sun.jsp.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspS
    ervlet.java:77)
    at com.sun.jsp.runtime.JspServlet$JspServletWrapper.service(JspServlet.j
    ava:87)
    at com.sun.jsp.runtime.JspServlet.serviceJspFile(JspServlet.java:218)
    at com.sun.jsp.runtime.JspServlet.service(JspServlet.java:294)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
    at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
    at com.sun.web.core.Context.handleRequest(Context.java:414)
    at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)
    HANDLER THREAD PROBLEM: java.net.SocketException: Socket is closed
    java.net.SocketException: Socket is closed
    at java.net.Socket.getInputStream(Socket.java:643)
    at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)

    Are you using JSWDK 1.0.1? If you are, then the implementation uses the Servlet Spec. 2.1. The set/getAttribute methods were added in 2.2.
    Try using the now-deprecated method putValue like this in SaveName.jsp.
    <%
    String name = request.getParameter( "username" );
    session.putValue( "theName", name );
    %>

  • Thread problems with Samsung D500? Http or https troubles?

    Hi!
    I've got some troubles with my application installed onto my D500, and I suspect that's maybe thread problem.
    Does anyone know something about thread problems for this phone?
    I want to know, is there any trouble for connecting application by using http or https?
    I've found one problem for E720 - it escapes "backslash" character when it's used as http parameter.
    It makes parsing troubles...
    Did anyone have some similer troubles, and how have you solved this problem?
    Thanks in advance,
    Alex

    When I'm trying to connect to the net by using my application, I get two errors: "TCP open" and "interruptedIOException", and so I suspect that's some kind of thread problems.
    On the other phones (Nokia, Sony Ericsson) this application works with no problems...

  • HANDLER THREAD PROBLEM?

    I'm trying to use the method Response.sendRedirect to forward users to another website. The actual case is irrelevant so I've extracted the important part into a simple servlet example:
    import javax.servlet.http.*;
    import java.io.*;
    public class ReDirect extends HttpServlet
       public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
          if(req.getQueryString()!=null)
             res.setContentType("text/html");
             res.getWriter().println("Your querystring: <b>"+req.getQueryString());
          else
             res.sendRedirect("http://java.sun.com");
    }The funny thing is that the servlet works FINE, but that darn thing is generating an IOException (showing in the DOS prompt of the webserver) everytime the sendRedirect method is called! Why?
    ReDirect: init
    HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
    java.io.IOException: Socket Closed
         at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:432)
         at java.net.Socket$1.run(Socket.java:335)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.Socket.getInputStream(Socket.java:332)
         at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)I have tried everything... I've also searched the forum for similar problems, but it seems that noone have a logic explanation for this. Is this a bug in the servlet engine or is it something I'm doing wrong or have forgotten?
    I'm using jswdk 1.0.1 and jdk1.3.1 on windows 2000, running the webserver that comes with jswdk.
    Please, someone, explain this to me! This problem is torturing me day and night!!
    /Stefan Westling

    Go get tomcat ...I used to get this error lot's when I used the jswdk. There are just some things it doesn't like ...yet when structured in certain way's ...it would work. I never did track down any consistent explanation. I just moved on to tomcat. The jswdk is really cheesy ...it can't do post ...or sessions ...or any 2.0 functionality ... or ... or ... Go get tomcat.

  • Java threading problem... threads only work on 1 processor

    I've got a iterative deepening problem that i have to parallelize. As far as i know i did everything correctly however everything seems to be running on 1 processor instead of 2 processors. As far as i know i am using threads (-Xprof either defines them as thread-1 thread-2 or pool1-thread1,depending on the method used for issueing)
    the worker thread is:
    public int solutionsT(Board board, int currentDepth) {
            int temp = 0;
            int result = 0;
            if (board.distance() == 0) {
               return 1;
            if (board.distance() > board.bound()) {
                return 0;
            Board[] children = board.makeMoves();
            result = 0;
            for (int i = 0; i < children.length; i++) {
                if (children[i] != null) {
                    temp = solutionsT(children, currentDepth + 1);
    if(temp != 0){
    result += temp;
    return result;
    public void run() {
    int temp =0;
    int i = 0;
    while(true){
    while(bag.size() !=0){
    bag.putSolution(solutionsT(bag.get(),1));
    try{   
    barrier.await();
    }catch(Exception e){}
    it get's it's input from a bag that is filled before the iteration begins. (once the bag is filled it trips a barrier) this worker thread is a implementation of Runnable
    This piece of code is used to make the thread object and to issue it
    public SolutionThread(int numberOfThreads) {
       thread = numberOfThreads;
       bag = new bagOfBoards();
       barrier = new CyclicBarrier(thread+1);
       if(thread > 1){
          ExecutorService threadExecutor = Executors.newFixedThreadPool( thread );
          solution = new ThreadTest[thread];
          bag = new bagOfBoards();
          for(int i = 0;i<thread;i++){
             solution[i] = new ThreadTest(bag, lock, barrier, i);
             threadExecutor.execute(solution);
    finally this is the code which is used to acces the bag and get a board.
    synchronized public Board get() {
                if (size > 0) {
                size--;
                Board result = bag[size];
                return result;
            } else {
             return null;
        }since this method is synchronized and it always returns something (either null or a board) and the worker tests for this. there is no race condition here.
    furter more. the main thread is a loop. It fills te bags with an intial state. then it trips the barrier and waits for the workers to do the work. the workers then process the bag until it hits zero and then trip the barrier so that the main thread can do the next iteration (and fill the bag)
    p.s. i know the code is a bit messy, but i want to get the threading to work. As of now i relaly don't understand why the threads are just running on 1 processor instead of 2 processors. not only that. the excecution time is nearly the same as that of a sequential equivalent.
    p.s.2 the code is parallisable. and it is run on a smp system.
    Message was edited by:
    jstrike

    i'm very sure that the jvm and os support smp. the
    problem really should be in the code.I don't see how this can be the case. There's nothing in the Java language that deals with how threads are assigned to processors (at least not as far as I know) so there isn't anything you can do in your code to affect that.
    Or did you meant that i have to tell the jvm in the class that
    there is support for multiple processorsThat would be the only possibility. I have no idea whether it can be done or not, though.

  • Multiple Threads Problem

    Hi,
    I am new to Java Threading and the current program that I am working is having problems. The program basically paints lines and dots or onto a JPanel which displays an image. There exists a thread here to suspend and resume the drawing at the user's disposal. This part works flawlessly.
    Now since the images are quite large I have attempted to add a JWindow to the JFrame to indiate that the image is loading. And here lies my problem, the JWindow which also contains a paint method does not display anything until after the image is fully loaded onto the JPanel.
    Can someone please tell me what I am doing wrong and how to implement this?
    Thanks, James
    Here is how my program is structured:
    public class Proj extends JFrame
    public Proj()
    Display disp = new Display();
    Thread thr1 = new Thread(disp);
    thr1.start();
    Container con = getContentPane();
    con.add(vsr);
    setSize(500,500);
    show();
    public static void main(String [] args)
    {  new Proj();
    class Display extends JPanel implements Runnable
    public Display()
    Loading ld = new Loading();
    Thread thr2 = new Thread(ld);
    ld.start();
    // gets data and image files
    ld.interrupt();
    public void paintComponent(Graphics g)
    // draws image, lines, circles etc.
    public void run()
    // involved with data to draw next image, lines etc.
    class Loading extends JWindow implements Runnable
    public void paint(Graphics g)
    // displays loading animation
    public void run()
    // animation code

    Since Swing is single-threaded, any painting activity after a component is realized/visible should be handled on the EDT (Event Dispatch Thread). The loading of data/files can be done on worker different thread. On the EDT you should fetch the status and paint your progress bar. If you paint the progress bar on the worker thread it would not work out the way you want. Try to also investigate into SwingUtilities.invokeLater method which allows us to put a code to be executed on the EDT.

  • Java.util.Timer and java.util.TimerTask running threads problem

    Hi,
    I have following scenario.
    1. My thread to send mail has to run at a fixed time interval thus I am using the following method from the Timer class.
    scheduleAtFixedRate(TimerTask object, start time, interval)
    2. My thread in the class checkDBSendEmail that extends TimerTask class reads database and sends mail based on the data received in the run() method.
    3. Whenever I send any mail, I log it into a database table that keeps the record of the emails sent.
    4. i have put it some logic to filter data form data base after that it will sends me unique data. Data should be email to different uses based on the list.
    Now the Problem:
    I am receiving duplicate mails on multiple times.
    Is there anything that I am missing in the following that would help me resolve this problem.
    my Servlet inti method is:

    sorry code is here..........
    public class SchduleTimeEmail extends HttpServlet implements SingleThreadModel{
    public void init( ServletConfig servletConfig ) throws ServletException{
    super.init(servletConfig);
    this.config = servletConfig;
    try{
    // specify in the format as in 12.13.52 or 3:30pm
    initialTime = format.parse( config.getInitParameter("initialTime"));
    delay = HOURS_24;
    RunLogger.addLogger("init first try:"); // log file
    catch( ParseException pe ){
    // Log.sendMessage( Log.MESSAGE_LEVEL_INFO , "[TimerServlet]", "startTime could not be parsed from web.xml file" );
    System.out.println("startTime could not be parsed from web.xml file."+pe);
    initialTime = new Date();
    delay = HOURS_24;
    // Timer Must start combination of 15,30,45,00 min for check schdule
    Date dalayTimeMinSec = new Date();
    int currentMin = dalayTimeMinSec.getMinutes();
    int totalDelayTime = 0;
    if(currentMin%15!=0 || currentMin%15 != 15){
    try {
    int delayMin = currentMin % 15;
    totalDelayTime = (15-delayMin) * 1000 * 60;
    dalayTimeMinSec.setSeconds(0);
    Thread.sleep(totalDelayTime);
    RunLogger.addLogger("Thread go for sleep:");
    } catch (InterruptedException ex) {
    RunLogger.addLogger(ex.toString());
    //Start Timer from this time
    timer = new Timer();
    Calendar time = Calendar.getInstance();
    Calendar timeOfDay = Calendar.getInstance();
    try{
    timeOfDay.setTime(initialTime);
    time.set((Calendar.HOUR_OF_DAY), timeOfDay.get(Calendar.HOUR_OF_DAY));
    time.set(Calendar.MINUTE, timeOfDay.get(Calendar.MINUTE));
    time.set(Calendar.SECOND, timeOfDay.get(Calendar.SECOND));
    Calendar startTimeOfTimer = Calendar.getInstance();
    startTimeOfTimer.add( Calendar.MINUTE, 0 );
    // make sure the first timer doesn't fire before the server starts
    if( time.before(startTimeOfTimer) )
    time = startTimeOfTimer;
    System.out.println("TimerServlet: Timer has been set for " + time.getTime() + " '(" + delay + ")'"); // for checking
    checkDBSendEmail msasTask = new checkDBSendEmail();
    timer.scheduleAtFixedRate( msasTask, time.getTime(), delay );
    catch( Exception e ){
    RunLogger.addLogger(e.toString());
    public void destroy(){
    timer.cancel();
    super.destroy();
    and another class is:..
    public class checkDBSendEmail extends TimerTask{
    public void run()
    // System.out.println("Function run : "+ functionExcuteCount++);
    try{
    // DB Logic as well as send e-mail function call
    catch( Exception ex ){
    RunLogger.addLogger(ex.toString());
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    public String getServletInfo() {
    return "Short description";
    // </editor-fold>
    I also checked the email server settings, and I am sure that the email server is not duplicating the emails.
    this code working correctly on my local machine But in live server it duplicating email and still I am receiving duplicate mails.
    Any help is appreciated.
    Thanks,
    Sharda

  • Threads Problem

    I had to adopt one project from someone, and he leave a warning message. " This package must be run using green threads . With native threads, this model will either run very slowly or crash. Green threads are made avialble in JDK 1.3.1( or earlier versions ) by running the program with java-classic "
    In the original program, it run for one replication. I had to modify this project running more than one replications or run one replication with long length. When I went to compile it I got this error. In the same program,sometime it can run, often it cannot. So, I'm not sure about the cause of this problem. What should I do, downgrade java version to 1.3.1 or modify the source code(I don't where is error or how to modify the code). Anyway, I'm just learning so take it easy on me.
    Can anyone please tell me how to fix the problem.
    Exception in thread "Thread-........" java.lang.NullPointerException
    at umontreal.iro.lecuyer.simprocs.SimThread.run(SimProcess.java:479) -----> this is the source code
    at java.lang.Thread.run(Thread.java:595)
    for .... , it had changed position for every run.
    Now, I use version 1.5 with NetBeans IDE4.1
    Regards,

    I had to adopt one project from someone, and he leave
    a warning message. " This package must be run using
    green threads . With native threads, this model will
    either run very slowly or crash. Green threads are
    made avialble in JDK 1.3.1( or earlier versions ) by
    running the program with java-classic "
    The person that left you this message shot be hunted down and shot.
    >
    Well a null pointer exception means you are going to have go plumbing around in the code.
    Here is my recommendation.
    Because it sounds like you have a real code mess on your hands (the description makes it sound like the orginial developer did something evil with synchronization and/or relying on thread timing) and because as you say you are just starting.. if downgrading to an older version will make it magically work then I suggest doing that as a stop gap.
    It is impossible for me to say without knowing alot more about your project but it sounds to me like your best course of action, and I mean this honestly to save you pain, is to examine the whole project and probably scrap and rewrite most of it if not all of it.
    Sorry for the bad news.

  • Java Threads Problem

    Hi, I am trying to write a simple java threads program where in one thread reads a file and another thread writes the data into a second file....
    Here is my code, although i think i am correct, my program still runs in a sequential fashion help help help!!!
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    class MyThread extends Thread{
    private int a;
    private int c;
    FileInputStream in;
    FileOutputStream out;
    public MyThread(int a){
    this.a = a;
    public void run(){
    if(this.a==5)
         try {
         in = new FileInputStream("Britney.txt");
    } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    try {
         while((c=in.read())!=-1)
              a = (char) c;
              System.out.println(a);
    catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    if(this.a==10)
         try {
              out = new FileOutputStream("romi.txt");
         } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
         for(int i = 0;i<50;i++)
              try {
                   System.out.println(c);
                   out.write(c);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    class MainMyThread{
    public static void main(String args[]){
    MyThread thr1, thr2;
    thr1 = new MyThread(5);
    thr2 = new MyThread(10);
    thr1.start();
    thr2.start();
    }

    Encephalopathic wrote:
    malcolmmc wrote:
    ... Chances of getting any kind of reply except "me too" can be pretty remote. ....there's actually a better chance of getting a reply on a general forum like this one, ....Can't you just post in both the narrow and the general forum, but include links one to the other in each thread? Or is that against the forum rules/etiquette? Most people here are ok with a crosspost IF those links are included.
    I would also ask that the OP designate one of those threads as the real discussion thread and just direct folks there from the other threads, so that we have one coherent discussion. If he does that, there's no problem with trying to reach out to as broad an audience as possible.
    I would figure that if the poster were upfront about what they are doing, folks wouldn't mind, but I could be wrong.I think that's generally the case. As long as the discussion is confined to one thread (and pointed there from the crossposts) or at the very least all the participants can see all the discussions, I think most people don't have a problem with it. It's when we waste our time answering when he's already got the answer elsewhere that's annoying.

  • Thread problem on windows xp

    Hi, all
    I have thread code looks like below. Under linux, I will see 'thread offline!' message when invoke offline method in myTask class. Under windows xp, I didn't see any output message. Does this mean thead still alive? Is it ok to controll a thread using code below? Why I got different result on these 2 platform?
    Thanks,
    Vincent Chen
    --- Main.java ---
    myTask task=new myTask();
    new Thread(task).start();
    <my code here>
    task.offline();
    --- myTask.java ---
    public class myTask extends Observable implements Runnable {
    boolean online;
    public myTask() {
    online=true;
    public void run() {
    while (online) {
    <my code here>
    System.out.println("thread offline!");
    public void offline() {
    online=false;
    }

    Append System.out.flush() right after println. This
    will make sure that text actually reaches console. I
    find it necessary on windows.flush should not be required after a println. Would the OP please follow-up whether it fixed the problem?

  • Another halting Thread problem

    Hello,
    I want to make a benchmark software using Java, and I want to add capability to stop the test if such setting was selected that the test would take forever. I know that I can do this with using such code like:
    public class MyBenchThread extends Thread {
    boolean toldToStop = false;
    public void run() {
      while (!benchmarkEndConditionHasMet && !toldToStop) {
       // Run heavy benchmark here
    public void haltTest() {
      toldToStop = true;
    }and calling haltTest() from another Thread.
    However, this has two problems:
    1) To have the benchmark at its purest level, I would like
    to avoid extra computation as much as possible. Is there a way to give the same effect of killing the thread without constantly checking a condition variable?
    2) If the benchmark involved some I/O operation (not necessarily over a socket to which you can set a timeout) that takes a while to complete, I would not be able to halt it using the above code or interrupt() function in Thread class. I know that stop() is likely to cause problem... So is there any way to force interrupt execution of the Thread including I/O, do whatever cleanup is needed, and gracefully exit?
    Thanks in advance

    Sorry for late response... Had been away for weekend.
    Well, interrupt() does not seem to work on I/O operation. It only works on a Thread that is actually sleeping or waiting on a monitor. If it was doing some heavy number crunching or I/O, I think it will only set its interrupted status to true, and does not actually suspend its operation. (This is my assumption; correct me if I am wrong)
    Hmm... so I guess there is not really a way to get around this. I was having problem with using a proprietary library that established a CORBA session inside it, and it did not provide any way of halting the operation externally. Unless I Ctrl-C whole VM, the library call just kept on going for about 30 secs till it finally gave up.
    I don't know... Is force trying to stop a problematic thread that dangerous thing in general to do in multiprocess programming, even if you knew what you were doing?

Maybe you are looking for