Client threads block forever in SSLSocketImpl.startHandshake

Hi --
We have an application which has 4 threads polling a webservice over HTTPS every 1-2 minutes. We don't control the server platform or webservice framework.
We've encountered a problem where one by one the threads stop polling. This has occurred 3 times, every time over a weekend (the busiest time for our polling). Each thread "freezes" at a different time; all 4 threads are "frozen" after about 24 hours.
JVM thread dumps suggests that the polling threads are blocked inside SSLSocketImpl.startHandshake; each one always has the same stacktrace within the JSSE & Axis libraries:
"SOAP Client Thread: Footy Feed" prio=5 tid=0x2877D388 nid=0x518 runnable [2c3af000..2c3afd8c]
     at java.net.SocketInputStream.socketRead0(Native Method)
     at java.net.SocketInputStream.read(SocketInputStream.java:129)
     at com.sun.net.ssl.internal.ssl.InputRecord.a(DashoA6275)
     at com.sun.net.ssl.internal.ssl.InputRecord.read(DashoA6275)
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
     - locked <0A931078> (a java.lang.Object)
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
     - locked <0A931068> (a java.lang.Object)
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275)
     at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:186)
     at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:131)
     at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:370)
     at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:88)
     at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
     at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
     at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
     at org.apache.axis.client.AxisClient.invoke(AxisClient.java:147)
     at org.apache.axis.client.Call.invokeEngine(Call.java:2719)
     at org.apache.axis.client.Call.invoke(Call.java:2702)
     at org.apache.axis.client.Call.invoke(Call.java:2378)
     at org.apache.axis.client.Call.invoke(Call.java:2301)
     at org.apache.axis.client.Call.invoke(Call.java:1758)
...(our application stacktrace)...
Client: JDK1.4.1-b21, JBoss 3.2.7RC1, Axis 1.2RC2, Win2k Server SP4, no client certificates
Server: Apache 1.3.29 (Unix) mod_ssl 2.8.16 OpenSSL 0.9.6j, mod_jk to Tomcat.
There's at least one firewall between client and server.
This problem appears similar: <http://issues.apache.org/bugzilla/show_bug.cgi?id=31832> & I've emailed the author.
I've googled a lot of forums for a solution without success.
Any help gratefully received.
Thanks
-- Richard Barnett

Thanks for the reply.
This case is different from that JMeter bug report as it's a SOAP request.
We're not explicitly setting a timeout, but Axis defaults to a 10 minute timeout on its requests. The source seems to indicate that this doesn't apply when creating SSL sockets (although it is used when creating regular sockets). No timeout occurs in any case.
-- Richard

Similar Messages

  • Weblogic 10 jsp compliation thread block problem

    hi
    i am using weblogic 10 and jdk1.5.
    My application is deployed in ear format, with 2 wars, and 20 ejbs.
    The ear works ok with weblogic 8.1.
    In the application , one war passes the request to another war, that's the workflow....
    Now when the request is passed on the second war, a jsp is supposed to open....but the application get stuck there.
    The call is like this in a servlet....
         reqDisp = req.getRequestDispatcher("/newIndex.jsp");
    reqDisp.forward(req, res);
    The new index jsp is not opened....there is no problem with it it comiples ok....i check with weblogic appc...and it is working on weblogic 8.1.
    when i stop the server...the log gives me following exception info.
    "ExecuteThread: '12' for queue: 'default'" daemon prio=6 tid=0x2b8edad0 nid=0xc1
    0 in Object.wait() [0x2da1e000..0x2da1fb64]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x07f94608> (a javelin.client.JobWaiter)
    at java.lang.Object.wait(Object.java:474)
    at javelin.client.JobWaiter.blockUntilFinished(JobWaiter.java:45)
    - locked <0x07f94608> (a javelin.client.JobWaiter)
    at javelin.client.ClientUtilsImpl.build(ClientUtilsImpl.java:838)
    at weblogic.servlet.jsp.JavelinxJSPStub.compilePage(JavelinxJSPStub.java:248)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:200)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:164)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:235)
    - locked <0x07ef8220> (a weblogic.servlet.jsp.JavelinxJSPStub)
    at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:391)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:309)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:503)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:245)
    at LCDisplayController.handleProcessing(Unknown Source)
    at DisplayControllerServlet.doPost(Unknown Source)
    at DisplayControllerServlet.doGet(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:503)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:245)
    at com.orbitech.workflow.servlet.WFAppListController.openWorkitem(WFAppListController.java:793)
    at com.orbitech.workflow.servlet.WFAppListController.processRequest(WFAppListController.java:102)
    at com.orbitech.workflow.servlet.WFAppController.doProcessRequest(WFAppController.java:97)
    at com.orbitech.workflow.servlet.WFAppController.doGet(WFAppController.java:64) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    i think the there is thread blocking and the jsp is not getting compiled or smthing....
    i am unable to understnd the exception....
    any help, suggestion ? thanks in advance.

    We are using jBPM and Hibernate in our application which runs fine on other java application servers. On Weblogic we were getting an error:
    org.hibernate.HibernateException: Errors in named queries: GraphSession...........
    By adding:
    <container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    to our weblogic.xml, Weblogic used our Hibernate3 and antl-2.7.6 .jar files which resolved this issue but created multiple CompilationException errors in many .jsp's. (as follows)
    Error 500--Internal Server Error
    weblogic.servlet.jsp.CompilationException: Failed to compile JSP /WEB-INF/jsp/struts/dashboards/portfolio_chart.jsp
    portfolio_chart.jsp:1:1: The validator class: "org.apache.taglibs.standard.tlv.JstlCoreTLV" has failed with the following exception: "java.lang.ClassCastException: weblogic.xml.jaxp.RegistrySAXParserFactory".
    <%@ taglib uri="/jstl-core" prefix="c" %>
    ^---------------------------------------^
    portfolio_chart.jsp:1:1: The validator class: "com.primavera.pvweb.taglib.JSMessageTagLibraryValidator" has failed with the following exception: "java.lang.ClassCastException: weblogic.xml.jaxp.RegistrySAXParserFactory".
    <%@ taglib uri="/jstl-core" prefix="c" %>
    ^---------------------------------------^
         at weblogic.servlet.jsp.JavelinxJSPStub.compilePage(JavelinxJSPStub.java:298)
         at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:216)
         at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:165)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:235)
         at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:394)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:309)
    Is this a Weblogic bug ?

  • Thread blocking on java.nio.charset.CoderResult

    Hello all,
    I have a multi-threaded app which does some fairly intestive string operations (basically extracts text from documents for indexing a search system).
    I am seeing a massive bottleneck around the java.nio.charset.CoderResult class. When profiling, I see a whole stack of threads blocking on (waiting for) a monitor on this java.nio.charset.CoderResult class. Seems to be a result of string encoding/decoding (I am often encoding strings as UTF-8).
    Anyone know why the JVM would want my threads to sync on this class? It's creating a huge performance issue for my app. Approximately 15% of ALL the processing time is spent waiting for this class.
    Help!

    I would guess that you're using some of the static methods in the CoderResult class. The static methods CoderResult.unmappableCache(), CoderResult.malformedForLength() and CoderResult.malformedCache all use a static inner class called Cache. Its get() method is synchronized on Cache.class. Since the Cache inner-class is static, any part of your multi-threaded application that goes through the Cache.get() method is going to be waiting for the lock on Cache.class.
    Could you create a CoderResult instance for each thread? That would mean that there would be a different static Cache class for each thread, reducing the number of threads competing for the Cache.class lock.
    I'd have to see some of your code to give a better answer.
    Brian

  • Thread Problem - (Thread Blocking Problems?)

    Hi Friends
    In my program while using thread i found a problem in this code .
    In this whlie running the 'msg' was printen only after all 5 inputs are given .
    why i was not getting output after one input.why the thread out was waiting for remaining threads input.
    my code is
    import java.io.*;
    class MyThread extends Thread
      BufferedReader bin;
       MyThread()
         super();
         start();
       public void run()
          try
           bin=new BufferedReader(new InputStreamReader(System.in));
           String msg=bin.readLine();
           System.out.println(msg);
          catch(IOException e)
             System.out.println(e);
    public class Threads
         public static void main(String args[])
              for(int i=0;i<5;i++)
                new MyThread();
    }

    Hi Friends
    In my program while using thread i found a problem
    em in this code .
    In this whlie running the 'msg' was printen only
    after all 5 inputs are given .
    why i was not getting output after one input.why
    hy the thread out was waiting for remaining threads
    input.Probably because of how the scheduler was rotating among the threads while waiting for input and queueing up output.
    When you call readLine, that thread blocks until a line is available. So it probably goes to the next thread's readLine, and so on. All threads are probably blocked waiting for input before you enter a single character.
    Something inside the VM has to coordinate the interaction with the console, and between that and your threads, the out stuff just doesn't get a chance to display right away.
    In general, you can't predict the order of execution of separate threads.

  • Thread blocked in printStackTrace

    I find one of my thread blocked in printStackTrace after perform an overload test. But it doesn't wait any java lock. So I don't know what happened.
    Part of dumped thread stack looked like this:
    "Thread: 553" daemon prio=5 tid=0x00598f68 nid=0x23f runnable [95d7f000..95d7fc28]
         at java.lang.Throwable.getStackTraceElement(Native Method)
         at java.lang.Throwable.getOurStackTrace(Throwable.java:591)
         - locked <0xc423b3a8> (a java.lang.Throwable)
         at java.lang.Throwable.printStackTrace(Throwable.java:510)
    My application runs on solaris, sparc machine. JVM is 1.4.2_04-b05.

    Can u pstack the process at this moment? The stacks of all the threads are probably too large to be shown here.
    Show the thread #575. i.e. nid = 0x23f, convert to decimal = 575, maybe its stuck in the native portion.
    Hope this helps.

  • [svn:bz-trunk] 12951: Changed synchronized PropertyProxyRegistry#getRegistry method to non-synchronized to avoid threads blocking in message push .

    Revision: 12951
    Revision: 12951
    Author:   [email protected]
    Date:     2009-12-15 02:17:31 -0800 (Tue, 15 Dec 2009)
    Log Message:
    Changed synchronized PropertyProxyRegistry#getRegistry method to non-synchronized to avoid threads blocking in message push.
    Checkintests: Pass with the usual 3-4 tests that time out with and without this change.
    QA: Yes
    Doc: No
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/io/PropertyProxyRegistry.java

    Revision: 12951
    Revision: 12951
    Author:   [email protected]
    Date:     2009-12-15 02:17:31 -0800 (Tue, 15 Dec 2009)
    Log Message:
    Changed synchronized PropertyProxyRegistry#getRegistry method to non-synchronized to avoid threads blocking in message push.
    Checkintests: Pass with the usual 3-4 tests that time out with and without this change.
    QA: Yes
    Doc: No
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/io/PropertyProxyRegistry.java

  • COMM outputstream blocking forever

    I am writing an application that talks with a modem through an RS232 serial port using the COMM packet on Windows.
    The problem is how to detect when the modem is not there for some reason. I discovered that the outputStream.write(...) function blocks forever. Is there a way to make it non-blocking, giving me a chance to do something else if no device is listening to the serial port?
    System.out.println("Writing to device");
    outputStream.write("AT".getBytes()); //  <- program hangs here if no device is present
    outputStream.write((byte) 0x0D);
    System.out.println("Done");
    //Then try to read AT....OK to see if modem is responding

    You should be able to check for the presence/absence of a modem by chacking the state of the incoming signals
    e.g. DSR=data set ready should be asserted if the modem is ready.
    You may find this link helpful
    http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html

  • Thread Blocked Problem

    I Have a multithread application which:
    - access to database
    - write files
    - read files
    - execute external process using exec
    What considerations should I take in order to avoid Threads Blocking? When Thread blocking occurs how can I know what is the cause?
    Thanks!
    T

    http://www.ibm.com/developerworks/library/j-thread.html
    - Saish

  • Login window blocks forever

    I have done a systemupgrade. Unfortunately during the upgrade my laptop shutdown (due to high temperature).
    I let the laptop cool down and tried to login again, but I just could enter my login name and the password and then the login widow blocked forever without any desktop coming up.
    I went to a textconsole, logged in and finished the upgrade (pacman -Syu) sucessfully. Then I entered "init 3" to kill the login window and started "startxfce4" without any problems. I changed my inittab to start with runlevel 3 only as a workaround.
    What can be wrong with the login window? Can anybody help?
    My /var/log/Xorg.0.log starts with:
    [   219.087]
    X.Org X Server 1.10.1
    Release Date: 2011-04-15
    [   219.087] X Protocol Version 11, Revision 0
    [   219.088] Build Operating System: Linux 2.6.38-ARCH x86_64
    [   219.088] Current Operating System: Linux lapi_acer 2.6.38-ARCH #1 SMP PREEMPT Tue May 3 07:40:34 CEST 2011 x86_64
    [   219.088] Kernel command line: root=/dev/disk/by-uuid/484885dc-96f3-4123-b2ab-ee75a61d5840 ro i915.modeset=0
    [   219.088] Build Date: 16 April 2011  12:02:01PM
    [   219.088] 
    [   219.088] Current version of pixman: 0.20.2
    [   219.088]    Before reporting problems, check http://wiki.x.org
            to make sure that you have the latest version.
    [   219.089] Markers: (--) probed, (**) from config file, (==) default setting,
            (++) from command line, (!!) notice, (II) informational,
            (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
    [   219.090] (==) Log file: "/var/log/Xorg.0.log", Time: Mon May  9 18:06:39 2011
    [   219.090] (==) Using config directory: "/etc/X11/xorg.conf.d"
    [   219.090] (==) No Layout section.  Using the first Screen section.
    [   219.091] (==) No screen section available. Using defaults.
    [   219.091] (**) |-->Screen "Default Screen Section" (0)
    [   219.091] (**) |   |-->Monitor "<default monitor>"
    [   219.091] (==) No monitor specified for screen "Default Screen Section".
            Using a default monitor configuration.
    [   219.091] (==) Automatically adding devices
    [   219.091] (==) Automatically enabling devices
    [   219.091] (WW) The directory "/usr/share/fonts/OTF/" does not exist.
    [   219.091]    Entry deleted from font path.
    [   219.091] (==) FontPath set to:
            /usr/share/fonts/misc/,
            /usr/share/fonts/TTF/,
            /usr/share/fonts/Type1/,
            /usr/share/fonts/100dpi/,
            /usr/share/fonts/75dpi/
    [   219.091] (==) ModulePath set to "/usr/lib/xorg/modules"
    [   219.091] (II) The server relies on udev to provide the list of input devices.
            If no devices become available, reconfigure udev or disable AutoAddDevices.
    [   219.091] (II) Loader magic: 0x7d6fa0
    [   219.091] (II) Module ABI versions:
    [   219.091]    X.Org ANSI C Emulation: 0.4
    [   219.091]    X.Org Video Driver: 10.0
    [   219.091]    X.Org XInput driver : 12.2
    [   219.091]    X.Org Server Extension : 5.0

    We cable internet users had similar problems in our neighborhood a while back. Sometimes the delay was there but more often than not, computers started OK. The system overview showed nothing wrong to the support types but one neighbor persisted and the techs found what they described as "confusing" reports on our node (takes in about four city blocks).
    They came out and worked on the node wiring and things returned to normal.
    The point is, sometimes the cable company doesn't know they have a local node problem until enough people rub their noses in it.

  • Want to create client threads.......

    I am a learner in Java!! Hey i am developing a client server application, such that many clients can connect to server. The clients connect asynchronously, so i want to know that how can i maintain the state of each client thread. I am bit confused if i should run the thread or the client. Just scrap me your idea so i can develop it. If you have and online code for it, Thanks a lot then!!

    Subashk wrote:
    Now i want to maintain the state of the client threads (to know what they are doing and the values)Define a Runnable that has member variables representing whatever you consider to be the "state" of your tasks.
    and also want to switch from one function to the other!!When you want to perform a parsing function, you call a parsing method. When you want to perform a validation function, you call a validation method. The usual way to do this is just call parse() and then validate() sequentially. After all, you can't validate until after you parse, so there's no point in putting those two in separate threads.
    I think you need to start from the very beginning with a multithreading tutorial. In any case, I don't think I can help you because it's not really clear what you're asking. (I don't think you have a clear enough grasp of the concepts involved to be able to ask meaningful questions.)
    Good luck!

  • Why happens when  threads block on I/O?

    I want to know what are the reasons for threads blocking on I/O.Do they block to allow the I/O operation or do they block(enter in waiting state) to allow other threads to continue operation while I/O opeation ?
    If a particular thread is blocked for I/O do other threads get a chance by the Thread Scheduler ?
    If this question has been asked and answered somewhere ,kindly let me know so that i can follow that thread.
    Thanks for your consideration.

    >
    Which thread is that which is "suspended"? The thread which is blocked waiting for the I/O will, um, wait for the I/O. That means it doesn't do anything else. It just waits. That's all. Is that not obvious?
    The "suspended" one is the one which is blocked waiting for the I/O.My question is when say the I/O is complete or the stream closes,won't the thread start executing again if given a chance by the scheduler ?
    Of course that doesn't affect any other threads. And what do you mean by "related to this thread"? There's no such concept. Each thread operates independently, except when they interact by holding locks or waiting for locks.
    "Related to this thread" means thread that share some common resources or say locks.Here i meant any other thread than the one which is blocked for I/O.
    Seems to me your mental model of threads is far too complicated. You need to get rid of all those imaginary concepts you're trying to insert there.That is what i am trying to simplify !!!!

  • Thread Blocking..help

    Hi All,
    I'm finding it hard to understand the concept of Threads blocking, for example, when u have a UI u'll want to run your main work in a different thread than in the event dispatcher thread as that will speed things up with the GUI.
    now let's say we have the following code:
    //Thread to prevent blocking and return control to GUI
    Runnable r = new Runnable() {
    public void run() {
    try
    ThreadThatDoesAlotOfWork.start();
    } catch (Exception e)
    e.printStackTrace();
    if I'll run it within a another thread within the GUI, howcome it doesn't block till all work is done?
    could u provide some code for blocking/non blocking threads..
    can u direct me maybe to helpfull docs somewhere..
    Thanks for the help and hope I'm being clear with my question..

    That article is about synchronisation access to variables by mutiple threads.
    I'm talking about using Threads for speeding things up...
    Thanks for the reply anyway..

  • Non-blocking Server/Client is blocking...?!

    First, a simple question:
    Why in most example code using Selectors, when iterating over the Set returned by Selector.selectedKeys() does the currently selected SelectionKey get removed from the Iterator? I see it all the time, but since the SelectionKey is still bound to the underlying Selector it seems to not really do anything.
    Now to my main problem:
    I been working with 1.4 for a week now trying to implement a simple test server/client, whereby the server constantly sends out the current time to any subscribing clients, who in turn display the time to stdout. Pretty straight forward, huh?
    Well, everything seems to go fine...once. The Server accepts the client connection, sends out a the current time, the client (only one for now) receives it, displays to the screen, but then both server and client block on the Selector.select() method.
    If I shut down the client, the server then continues through the select() method, finding one SelectionKey, tries to write to it and throws an IOException (since the client is no more). I'm catching that exception and then removing the channel from the Selector, so that the server may continue to service requests.
    When starting a second client while the first is still running causes the following sequence of events:
    Server: starts up
    ClientA: connects to server
    Server: broadcasts the time
    ClientA: displays time
    // nothing else happens until...
    ClientB: connects to server
    Server: broadcasts the time
    ClientA: displays time
    ClientB: displays time
    //everything blocks again...
    ClientA: disconnects from server
    Server: broadcasts the time
    ClientB: displays time
    As you can see it seems everything blocks until a client does something (connect/disconnect).
    I will post code if anyone asks, but I don't want to spam the board if no one is willing to help me.
    -Justin

    You got it!
    //   ********** SERVER **********
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.nio.ByteBuffer;
    import java.nio.channels.CancelledKeyException;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Set;
    public class TestServer
      private static final int DEFAULT_PORT = 9999;
      public static void main(String[] args)
        TestServer s = new TestServer();
      }//end of main(String[])
      public TestServer()
        this(DEFAULT_PORT);
      }// end of TestServer()
      public TestServer(int port)
        InetSocketAddress addr = new InetSocketAddress(port);
        try
          Selector acceptSelector = Selector.open();
          Selector broadcastSelector = Selector.open();
          ConnectionList connections = new ConnectionList(broadcastSelector);
          Acceptor a = new Acceptor(acceptSelector, addr, connections);
          Broadcaster b = new Broadcaster(broadcastSelector, connections);
          a.start();
          b.start();
        }// end of try
        catch (Exception ex)
          ex.printStackTrace();
        }// end of catch
      }// end of TestServer(int)
      private static String status(Selector s)
        StringBuffer sb = new StringBuffer(100);
        sb.append("Selector: ");
        Set keys = s.keys();
        sb.append("\n\tNum Keys: ");
        sb.append(keys.size());
        Iterator iter = keys.iterator();
        int i = 0;
        while (iter.hasNext())
          try
            sb.append("\n\t[");
            sb.append(i++);
            sb.append("]:");
            SelectionKey key = (SelectionKey)iter.next();
            sb.append(" acceptable=");
            sb.append(key.isAcceptable());
            sb.append(" connectable=");
            sb.append(key.isConnectable());
            sb.append(" readable=");
            sb.append(key.isReadable());
            sb.append(" writable=");
            sb.append(key.isWritable());
          }// end of try
          catch (CancelledKeyException cke)
            sb.append("*** CANCELLED KEY");
          }// end of catch
        }// end of while
        return sb.toString();
      }// end of status(Selector)
      class Broadcaster extends Thread
        private final String TF = Broadcaster.class.getName();
        private int BUFFER_SIZE = 2048;
        private Selector selector_;
        private ConnectionList connections_;
        private ByteBuffer buffer_;
        public Broadcaster(Selector selector, ConnectionList connections)
          super("Broadcaster");
          selector_ = selector;
          connections_ = connections;
          buffer_ = ByteBuffer.allocateDirect(BUFFER_SIZE);
        public void run()
          while (true)
            try
              registerNewChannels();
              System.out.println("BroadcasterThread: Before select() "+status(selector_));
              System.out.println("BroadcasterThread: Selecting...");
              int keysReady = selector_.select();
              System.out.println("BroadcasterThread: After select() "+status(selector_));
              System.out.println("BroadcasterThread: "+keysReady+" ready Key(s)");
              if (keysReady > 0)
                transmit();
              }// end of if
            }// end of try
            catch (Exception ex)
              ex.printStackTrace();
              return;
            }// end of catch
          }// end of while
        protected void registerNewChannels()
        throws Exception
          SocketChannel channel = null;
          while (null != (channel = connections_.removeFirst()))
            channel.configureBlocking(false);
            channel.register(selector_, SelectionKey.OP_WRITE);
            System.out.println("BroadcasterThread: Registered connection from " + channel.socket().getInetAddress());
          }// end of while 
        }// end of registerNewChannels()
        public void transmit()
        throws Exception
          Set readyKeys = selector_.selectedKeys();
          System.out.println("BroadcasterThread: Selected Keys: "+readyKeys.size());
          SelectionKey tempKey = null;
          SocketChannel tempChannel = null;
          fillBuffer();
          for (Iterator i = readyKeys.iterator(); i.hasNext(); )
            tempKey = (SelectionKey)i.next();
            tempChannel = (SocketChannel)tempKey.channel();
            if (tempKey.isWritable())
              System.out.println("BroadcasterThread: Key selected is Writable");
              try
                tempChannel.write(buffer_);
                System.out.println("BroadcasterThread: Sent message to "+tempChannel.socket().getInetAddress());
              }// end of try
              catch (IOException ioe)
                System.err.println("BroadcasterThread: Lost Connection");
                tempChannel.close();
              }// end of catch
            }// end of if
            else
              System.out.println("BroadcasterThread: Key selected is not Writable");
            }// end of else
          }// end of for
          buffer_.clear();
        }// end of transmit()
        private void fillBuffer()
          buffer_.clear();
          /* Place Date in Buffer */
          long time = System.currentTimeMillis();
          Date d = new Date(time);
          System.out.println("BroadcasterThread: Broadcasting "+d);
          String date = d.toString()+"\n";
          byte[] datebuff = date.getBytes();
          buffer_.put(datebuff);
          /* Prepare for read operations */
          buffer_.flip();
        }// end of fillBuffer()
      }//end of inner class Broadcaster
      class Acceptor extends Thread
        private Selector selector_;
        private ConnectionList connList_;
        private final String TF = Acceptor.class.getName();
        public Acceptor(Selector selector, InetSocketAddress address, ConnectionList connList)
          super("Acceptor");
          selector_ = selector;
          connList_ = connList;
          try
            ServerSocketChannel ssc = ServerSocketChannel.open();
            ssc.configureBlocking(false);
            ssc.socket().bind(address);
            System.out.println("AcceptorThread: Bound to " + address);
            ssc.register(selector_, SelectionKey.OP_ACCEPT);
          }// end of try
          catch (Exception ex)
            ex.printStackTrace();
          }// end of catch
        public void run()
          while (true)
            try
              System.out.println("AcceptorThread: Selecting...");
              int keysReady = selector_.select();// block till a channel is ready
              System.out.println("AcceptorThread: "+keysReady+" Keys Ready");
              if (keysReady > 0)
                acceptPendingConnections();
              }// end of if
            catch (Exception ex)
              ex.printStackTrace();
        protected void acceptPendingConnections()
        throws Exception
          Set readyKeys = selector_.selectedKeys();
          System.out.println("AcceptorThread: Selected "+readyKeys.size()+" Keys");
          for (Iterator i = readyKeys.iterator(); i.hasNext(); )
            SelectionKey key = (SelectionKey)i.next();
            i.remove();  
            ServerSocketChannel readyChannel = (ServerSocketChannel)key.channel();
            SocketChannel incomingChannel = readyChannel.accept();
            System.out.println("AcceptorThread: Connection from " + incomingChannel.socket().getInetAddress());
            connList_.add(incomingChannel);
          }// end of for
        }// end of acceptPendingConnections()
      }// end of inner class Acceptor
      class ConnectionList
        private LinkedList list_;
        private Selector selectorToNotify_;
        public ConnectionList(Selector toNotify)
          list_ = new LinkedList();
          selectorToNotify_ = toNotify;
        }// end of ConnectionList(Selector)
        public synchronized void add(SocketChannel newlyConnectedChannel)
          list_.add(newlyConnectedChannel);
          selectorToNotify_.wakeup();
        }// end of add(SocketChannel)
        public synchronized SocketChannel removeFirst()
          SocketChannel first = null;
          if (list_.size() > 0)
            first = (SocketChannel)list_.removeFirst();
          }//end of if
          return first;
        }// end of removeFirst()
      }// end of inner class ConnectionList
    }// end of class TestServer
    //   ********** CLIENT **********
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.channels.CancelledKeyException;
    import java.nio.channels.Channels;
    import java.nio.channels.ReadableByteChannel;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.WritableByteChannel;
    import java.util.Iterator;
    import java.util.Set;
    public class TestClient
      public static final String TF = TestClient.class.getName();
      private static final String DEFAULT_SERVER_IP = "127.0.0.1";
      private static final int DEFAULT_SERVER_PORT = 9999;
      private InetSocketAddress serverAddr_; 
      private Selector connectSelector_;
      private Selector readSelector_; 
      private WritableByteChannel outputChannel_; 
      private ByteBuffer receiveBuffer_;
      private SocketChannel serverChannel_;
      public static void main(String[] args)
        TestClient c = new TestClient();
      }// end of main(String[])
      public TestClient()
        this(DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT);
      }// end of TestClient()
      public TestClient(String ip, int port)
        try
          serverAddr_ = new InetSocketAddress(ip, port);
          connectSelector_ = Selector.open();
          readSelector_ = Selector.open();
          outputChannel_ = Channels.newChannel(System.out);
          receiveBuffer_ = ByteBuffer.allocateDirect(512);
          connect();
          run();
        }// end of try
        catch (Exception ex)
          ex.printStackTrace();
        }// end of catch
      }// end of TestClient(String, int)
      private void connect()
      throws Exception
        serverChannel_ = SocketChannel.open();
        serverChannel_.configureBlocking(false);
        serverChannel_.connect(serverAddr_);
        serverChannel_.register(connectSelector_, SelectionKey.OP_CONNECT);
        int numKeys = 0;
        while (numKeys <= 0)
          System.out.println("connect(): Selecting...");
          numKeys = connectSelector_.select();
          System.out.println("connect(): "+numKeys+" ready Key(s)");
          Set readyKeys = connectSelector_.selectedKeys();
          System.out.println("connect(): Selected Keys: "+readyKeys.size());
          if (numKeys > 0)
            SelectionKey tempKey = null;
            SocketChannel tempChannel = null;
            Iterator i = readyKeys.iterator();
            while (i.hasNext())
              tempKey = (SelectionKey)i.next(); 
              i.remove();  
              tempChannel = (SocketChannel)tempKey.channel();
              if (tempKey.isConnectable())
                System.out.println("connect(): Key selected is Connectable");
                if (tempChannel.isConnectionPending())
                  System.out.println("connect(): Connection Pending");
                  tempChannel.finishConnect();
                  System.out.println("connect(): Connection Completed");
                }// end of if
              }// end of if
              else
                System.out.println("connect(): Key selected is not Connectable");
              }// end of else
            }// end of while
          }// end of if
        }// end of while
      }// end of connect()
      private void run()
      throws Exception
        serverChannel_.register(readSelector_, SelectionKey.OP_READ);
        while (true)
          System.out.println("run(): Before select() "+status(readSelector_));
          System.out.println("run(): Selecting...");
          int numKeys = readSelector_.select();
          System.out.println("run(): After select() "+status(readSelector_));
          System.out.println("run(): "+numKeys+" Ready Key(s)");
          if (numKeys > 0)
            processKeys();
          }// end of if
        }// end of while
      }// end of run()
      private void processKeys()
      throws Exception
        Set readyKeys = readSelector_.selectedKeys();
        System.out.println("processKeys(): Selected Keys: "+readyKeys.size());
        SelectionKey tempKey = null;
        SocketChannel tempChannel = null;
        for (Iterator i = readyKeys.iterator(); i.hasNext(); )
          tempKey = (SelectionKey)i.next();
          tempChannel = (SocketChannel)tempKey.channel();
          if (tempKey.isReadable())
            System.out.println("processKeys(): Key selected is Readable");
            try
              tempChannel.read(receiveBuffer_);
              receiveBuffer_.flip();
              outputChannel_.write(receiveBuffer_);
              receiveBuffer_.clear();
            }// end of try
            catch (IOException ioe)
              System.out.println("processKeys(): Lost Connection");
              tempKey.cancel();
            }// end of catch
          }// end of if
          else
            System.out.println("processKeys(): Key selected is not Readable");
          }// end of else
        }// end of for
      }// end of processKeys()
      private static String status(Selector s)
        StringBuffer sb = new StringBuffer(100);
        sb.append("Selector: ");
        Set keys = s.keys();
        sb.append("\n\tNum Keys: ");
        sb.append(keys.size());
        Iterator iter = keys.iterator();
        int i = 0;
        while (iter.hasNext())
          try
            sb.append("\n\t[");
            sb.append(i++);
            sb.append("]:");
            SelectionKey key = (SelectionKey)iter.next();
            sb.append(" acceptable=");
            sb.append(key.isAcceptable());
            sb.append(" connectable=");
            sb.append(key.isConnectable());
            sb.append(" readable=");
            sb.append(key.isReadable());
            sb.append(" writable=");
            sb.append(key.isWritable());
          }// end of try
          catch (CancelledKeyException cke)
            sb.append("*** CANCELLED KEY");
          }// end of catch
        }// end of while
        return sb.toString();
      }// end of status(Selector)
    }// end of class TestClient

  • Archiver  Issue| Automatic replication process | Archiver thread blocking

    Hi,
    Recently, we are facing a strange issue with Archiver auto replication process. Sometime, archiver thread is blocking and auto replication is stalling. We observed this issue after we apply latest OUCM patches downloded from Oracle support site.
    As an work around, we are doing UCM restart.
    Anybody got this kind off issue? We are following this up with Oracle in parallel. Any help regarding this is highly appreciated.
    Gowtham J

    What version/patch set/core update of UCM are you using?
    Jonathan
    http://redstonecontentsolutions.com
    http://corecontentonly.com

  • Future.get and the event despatch thread blocking

    neeeyaaarghhhh
    been tying myself in knots thinking about this
    Following one of the java tech tips I've been using Callable and Future objects when I want to return a result from a task, in my case it's usually some file processing
    So I have a file chooser gui, I select a file and launch my Callable and await the result in Future.get...
    Now the problem is... Future.get I understand blocks the calling thread until the computation / work in the Callable is done and the result returned. In this case the blocked thread will be the event despatch thread... which causes problems as during my file reading I have a JProgressBar running and updating. Well at least I did, now it doesn't show up at all as all the updates to the JProgressBar via invokeLater are queued (as event despatch thread is blocked) until after the work thread has finished
    How do I launch a Callable, await the result and have some limited gui activity as the task progresses? The only solution I've found is to have the ProgressBar in a modal dialog, to block out the rest of the gui like this whilst I do the work in the event despatch thread (and drop the idea of threading altogether)
    Is my mental modal of how worker threads should spin off from the event thread flawed or am I just missing some 1 line command?

    In the situation of updating the gui, you usually want to pass some sort of callback object to the asynchronous code and have that callback method run on the gui event thread.
    public class GuiClass {
    public void handleResult(Object data);
    public void startTask() {
      threadpool.execute(new Runnable() {
        public void run() {
          // ... do asynch work ...
          final Object myResult = ...;
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              handleResult(myResult);
    }In this code, the startTask method is called on the gui thread. it starts some async work on the threadpool. when finished, the asynch task queues the result to be handled back on the gui thread. the handleResult method is called later on the gui thread with the final result. thus, no blocking of the gui thread.
    The Callable interface is great for when the invoking thread needs to wait for a result, but you pretty much never want to do this with the gui thread.

Maybe you are looking for

  • EPS files

    What do I have to download to view a EPS file?

  • Why doesn't reply arrow find my reply?

    When I click the curly arrow which should take me to the reply that I typed to an email, it tells me what it can't find the reply and that I may have deleted it. However, when I check in the Sent mail folder, there is my reply. Why can't Mail find it

  • Adobe Cloud doesn´t start on windows start?

    Hello, the cloud doesn´t start anymore with windows. Settings are ok. Is there any service that must run? At the windows autostart config no entry about the cloud. Any idea? Thx for help best wishes

  • Stock transport PO process

    Dear Gurus, I have a very critical issue at my hand.I am breaking my head on this issue  kindly help me in resloving this issue. PO is raised for Qantity 5 by Reciving plant (A) Stock is avilable in Supplying plant (B) 500 ( make to stock ) In MD04 r

  • Help - cannot access moved workspace

    Hi all, I have just moved my Flex projects from my E: drive to my C: drive, and removed my E drive with Partition Magic. When I start FB3 it tells me the workspace cannot be found - as expected - and prompts me for a new location. I give it the locat