Stopping a blocked Thread

I need to stop a Thread, or interrupt a blocked I/O.
I'm making a call to a library that I do not own and cannot change. The library makes a HTTP connection to a service and waits for a response. As far as I know, the library uses BufferedReader to read the service response. If the service is down, then no response is ever returned, and the BufferedReader read simply blocks.
I cannot change the library to be intelligent, of course, and don't have very good luck getting the service support to fix their stuff. But I have to use the library. How can I interrupt the blocked I/O read?
What I've tried is as follows, but I'm not convinced it's the right way. My application is a long-running application that does not exit very often, so I'm concerned also about gc not properly recycling the resources due to still having the blocked thread still there (and this has impacted subsequent executions, even though I use local variables where I can).
        // Create a new Thread to wait on the submission
        Thread t = new Thread() {
            public void run() {
                response = event.submit();
        t.setDaemon(true);
        t.start();
        try {
            t.join(timeOut);
            msg = "Attempt to connect to ESM Server timed out";
        catch (InterruptedException e) {
            msg = e.getMessage();
        }The other option I was thinking of, was coding my call to ESM server in a separate Class with a main, and invoking it via Runtime.exec. That way, at least I'm 100% sure that the code exits, and I can use System.out/err to receive the "output".
Given that Thread.stop() is deprecated, and that you theoretically cannot interrupt blocked I/O, how have others solved this problem?
Thanks,
Matt

...you theoretically cannot interrupt blocked I/O, how have others solved this problem?I've done it your way. Each thread does an access. If it takes too long, then it may never respond and I ignore it. I also log the error condition and try to notify and administrator.
Threads probably take up about a megabyte of memory so I may run out of memory it the problem doesn't get fixed by manual intervention.
Your idea of using Runtime means that you create a new JVM for each ESM. If a thread takes up a megabyte, the new JVM takes up many, many megabytes. Instead of running out of memory in the JVM, you may run out of memory in the Box.
Every situation is different. My thread approach works for my application. What works best for you is your call.

Similar Messages

  • (J2ME) Stopping a blocked thread

    In J2ME, receiving a datagram blocks the current thread until a datagram is received. I have created a thread that simply receives a datagram and then loops waiting for the next one. How do I stop the thread when it is blocking in datagram receive waiting for a datagram to come in? I am using the code on http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html for a reference, and it mentions calling Thread.interrupt() but this method does not exist in J2ME.

    I tried searching for any API on J2ME... it looked like there were a lot of different specifications, and in any case I never found any API docs.
    However, i did want to say this:
    In regular java, the way you would normally do this is (ThreadObj).interrupt(), but you said this didn't exist. Are you 100% sure?
    If that's not working, I have 2 other ideas:
    1. Thread.stop() - it has been deprecated and is not technically "safe" but it could probably work in a pinch.
    2. There is often a way to put a timeout on an inputstream. See if you can do that.

  • Stop an OSGi thread

    Hi everyone!
    I am programming a OSGi bundle using Eclipse. The problem is that I don't know how to use the stop method in the Activator class so my program does never stop and I have to stop it by hand. For example:
    public void start(BundleContext context) throws Exception {
          System.out.println("Starting bundle"); }
    public void stop(BundleContext context) throws Exception {
         }The console shows the Starting bundle message but instead of stopping the program after doing the only thing it must do, it does not stop. What should I write in the stop thread so that the program after showing the message stops?
    Thanks in advance!

    What exactly are you trying to do? Calling Thread.stop( ) is inherently a bad idea (see the Javadocs).
    You are getting a IllegalStateException because Thread.stop( ) kills the thread, you would need to create a new thread to resume execution.
    If what you are trying to do is pause execution, you probably want to redesign your thread's tasks into smaller chunks that can be launched separately. Alternatively, have the thread check it's interrupted state and if a flag was set block on a monitor until you want it to resume execution.

  • Stop the running Thread

    Hi
    i am calling the thread .in the midlle of running thread i have to stop the thread .please help me .
    my senario like . I am calling the scripts . i am wating certain period to complete the script exection . if the scripts are not available its still wating for a long time . so i am using the thread to execute the scripts and (main thread )checking each duration is completed or not . if the duration completed i am stoping the thread with Thread.Stop() method . but the thread still is alive . next time when i call Thread.Start() its throwing "java.lang.IllegalThreadStateException".
    please help me this .
    Thanks in advance
    public class TestCaseScriptProcessor extends Thread {
    public String execute(){
    TestCaseScriptProcessor caseScriptProcessor = new TestCaseScriptProcessor();
    caseScriptProcessor .start();// second time throwing java.lang.IllegalThreadStateException.
    while (!isExpired) {
    caseScriptProcessor.stop();
    public void run() {
    Edited by: 849614 on Jan 17, 2013 6:17 AM
    Edited by: 849614 on Jan 17, 2013 6:22 AM

    What exactly are you trying to do? Calling Thread.stop( ) is inherently a bad idea (see the Javadocs).
    You are getting a IllegalStateException because Thread.stop( ) kills the thread, you would need to create a new thread to resume execution.
    If what you are trying to do is pause execution, you probably want to redesign your thread's tasks into smaller chunks that can be launched separately. Alternatively, have the thread check it's interrupted state and if a flag was set block on a monitor until you want it to resume execution.

  • I have multiple devices with the same cerificate, once I have a an exception for one, FF denys access to the others. I cannot change the certificates, I need to stop FF blocking them.

    I have multiple devices with the same cerificate, once I have an exception for one, FF denys access to the others. I cannot change the certificates, I need to stop FF blocking them.
    == This happened ==
    Every time Firefox opened
    == I attempt to access a web front end on an IBM SVC device

    You can't use the same certificate more than once.
    See also [[Certificate contains the same serial number as another certificate]]

  • How to stop modal blocking in adf dialogs?

    How to stop modal blocking in adf dialogs?
    blocking="false" has no effect.
    <af:commandLink id="showRequestDetail"
    action="dialog:guide.sa_requestDetail" partialSubmit="true"
    actionListener="#{shareAccessRequestDetail.load}"
    useWindow="true" blocking="false" immediate="true">

    Scratch that...useWindow was there -- it just wasn't popping a window when a non-dialog action was specified.
    <af:commandLink action="userDetail" partialSubmit="true"
    windowHeight="600" windowWidth="500" actionListener="#{userDetail.load}"
    useWindow="true">
    <af:outputText value="#{row.Efirstname}"/>
    </af:commandLink>
    The above code does not pop a new window despite the fact that useWindow is true.

  • Obtaining monitor lock of a blocked thread

    Is there a way to obtain the monitor lock (reference to the object) of a blocked thread? Something like Object Thread.getMonitorLockedObject()Also when you get the locked object it would be useful if you can get reference to the thread which is holding it, e.g.
    Thread Object.getLockingThread() although the latter could be achieved through iterating over all threads and calling boolean Thread.holdsLock(Object)Such methods would help very much in debugging deadlocks and other concurrency problems.

    <pre>
    Is there a way to obtain the monitor lock (reference
    to the object) of a blocked thread? Something like
    Object Thread.getMonitorLockedObject()
    Not that I'm aware of, and a quick glance through the APi didn't look promising.
    Also when you get the locked object it would be
    useful if you can get reference to the thread which
    is holding it, e.g.
    Thread Object.getLockingThread()although the latter could be achieved through
    iterating over all threads and calling boolean
    Thread.holdsLock(Object)
    Again, no. And your work-around wouldn't work, since the holdsLock method is static and can only be called for the current thread.
    Such methods would help very much in debugging
    deadlocks and other concurrency problems.There already are some useful methods for that in the Thread class, e.g. getState() and getAllStackTraces().
    </pre>

  • How to see and clear the blocked threads

    Where can I see how many threads are currently running and how many threads are blocked and how many are in idle status.
    Where can I see all these information and if I want to kill the blocked threads how to do that
    Thanks in advance

    This can be found in Weblogic Log folder..

  • Cannot stop memory monitor thread

    Hi All,
    I am getting the following error intermittently in a dataflow which has degree of parallelism = 8.
    22943 0 SYS-170111 27/11/2009 12:22:05 |SubDataflow DF_Conform_ISI_Person_Match_Prep_1_9
    22943 0 SYS-170111 27/11/2009 12:22:05 Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>
    Any ideas as to the cause ?
    Thanks,
    Eric Jones.

    We are having the same issue.
    According to ADAPT00890818, this issue should be resolved in 12.0.0. We are currently running with version 12.2.2.3.
    Please advice.

  • I have several times tried to stop following a thread in the PDF's forum about security issues and i still keep getting flooded with emails from this thread. I used the action within the thread that says stop following but appears to have no effect I stil

    I have several times tried to stop following a thread in the PDF's forum about security issues and i still keep getting flooded with  emails from this thread. I used the action within the thread that says stop following but appears to have no effect I still keep  getting from 5 to 20 emails daily. Please help!!!!!!!

    This may be helpful: How do I disable email notifications?

  • Blocked threads

    Hi, I need help to solve the following problem:
    I have a thread T calling a method x() of a class C.
    The problem is that, by my point of view, the method C.x() is an atomic function and it could be blocking or it could take too much time.
    Now I need to kill the thread after a while (i.e. after timeout expiration).
    I know that the Thread.close() method is deprecated and that, in this case, Thread.interrupt() can't solve the problem (I can't use status variables).
    I've also read something about java.nio package but I don't know how to use it.
    Is there anybody can help me?
    Thanks

    I'm implementing a simple server that gets request from clients.
    Clients open a socket connection on a well known port.
    When the server receives a new connection request it creates a new thread.
    This thread is in charge to receive, parse the commands coming from the client (via socket). Based on the request it calls the related method for the class. Normally the method is a call for a CORBA object's function. And the problem is that the response (that is, the function has finished) could come after a while and it is out of my control (for example CORBA objects has problems or the request itself takes time).
    After timeout expiration I need to kill all the blocked threads, because the server must handle a maximum number of threads, and if I don't kill blocked threads no other clients (requests) are admitted.
    thanks for your help
    d.

  • SYS-170111 - Cannot stop memory monitor thread: RWThreadImp::terminate -

    Hi Experts,
                  WE have this warning in pretty much every job in production. But the warnings are not specific to certain jobs they might occur one day and not the other day.
    Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>.
    I know looking at the release notes this issue was fixed in 3.0 (12.0.0), we are using 3.2 (12.2.0) and having the same issues. The job server is on a linux 64 bit. I have not seen this issue in any of our windows job server. Is this bug specific to linux or is there a resolution for this.
    Appreciate your help in advance.
    Thanks
    AJ
    Edited by: alangilbi on Sep 28, 2011 5:17 PM

    Hi, AJ.
    As can be seen in the KBA 1455412 this is a known behavior.
    "As a result of fixing the problem identified in ADAPT 00890818 in release 12.0.0.0, this message is displayed by design. If there is really a problem in stopping the memory monitor thread an exception is thrown and an error message is logged.
    Background:
    In the memory monitor's shutdown logic, once it tells the monitor thread to shutdown it waits for the thread to terminate but only for 10 seconds. It could be that at this same time the wait expired when the thread actually terminates. So when this happens in the shutdown logic we force terminate the thread. Since there is no active thread anymore the terminate call throws an exception and then we catch it and then throws the error for the job."
    You can just ignore this warning.
    Leo.

  • How do I STOP & DESTROY a thread?????

    I cannot seem to get my wait cursor to work. Sometimes it appears, sometimes it doesn't. After searching the forums I saw that I must put my long computational code in a seperate thread to get my wait cursor to be painted...
    My question is: How do you stop & destroy a thread? Or will it automatically stop/destroy itself when done running?

    Currently, what I am doing is:
    //set cursor
    public void run() {
    //long process
    //set cursor to normal
    This seems to work fine, but I just wanted to make sure there is not stop/destory method. I didn't want 50 empty thread floating around. I am new to using threads...
    Thanks!

  • CPU going 100%. Can blocked thread may be a reason?

    Hi Team,
    May be a dumb question. In my application around 40 threads are in blocked state and CPU is going about 100%. Is blocked threads may be reason for that? As threads are blocked, CPU should not be busy entertaining them, that is the reason why this question came in mind. Can somebody clear my this doubt.
    Thanks in advance.

    I encounter the same problem, although I run Berkeley DB (Ver 6.0.20, C#) under .NET Framework and Windows server 2008(x64). Any BDB application of win32 runs well but will encounter trouble under platform of x64 when compile BDB to x64, even though the DLL compiled and linked with win32. The bug is that Berkeley DB take amount of memory as the size of databases and regardless of cacheSize. My estimation is that all memory for BDB malloced and NOT freed.

  • WLS 8.1sp3 blocked threads halt MDB processing

    Under Weblogic Server 8.1 SP3 JMS consumers stop processing the JMS queues. This only started happening following our upgrade from SP2. We had numerous test baselines as well as months of production data to validate this.
              Specifically it appears that internal weblogic threads are blocked, preventing the MDBs (JMS consumers) from being dispatched. This doesn't immediately impact the user experience, but eventually unprocessed JMS messages accumulate and consume heap. You can figure out the rest.
              We had 5 MDBs working on this particular JMS queue, so under moderate traffic all 5 would need to be blocked before the problem was realized.
              As a work around, you'll need to request a patch from BEA. CR188391 appears to resolve this issue. You must request this however. BEA will not contact you - regardless of functional or economic impact.
              Thanks
              -Sean

    Sean,
              I've forwarded your comments internally. Usually, one can look in the release notes of future service-packs to see what's been fixed. I would think upgrading from SP3 to sp4, or even sp5 (the latest) would also have fixed the problem.
              Tom, BEA

Maybe you are looking for