Note that there are some explanatory texts on larger screens.

plurals
  1. POBest Practice for killing a JavaME 1.2 thread?
    primarykey
    data
    text
    <p><strong>Question:</strong> I'm interested to know the best practice for killing a long standing operation that is running as a background thread (lets call this thread <code>WorkerThread</code>) in Java 1.2.</p> <h3>Scenario</h3> <p>Specifically, I'm developing an application for Blackberry devices whereby I make a HTTP connection. Big picture: a URL request if forwarded to a background thread (<code>WorkerThread</code>), the thread makes the request and returns the result using a call back.</p> <h3>Scenario Details</h3> <p>Now there exists a situation where at connection time, a data connection exists <strong>but then</strong> for whatever reason (drives through a tunnel) that connection no longer exists. Due to a limitation in Blackberry's design architecture, that actual connection will hang as the time out is fixed to be 2 minutes. As a result, there's a crucial need to kill a connection that has been hanging for a relatively (15 seconds) long period of time. </p> <h3>My Current Solution - 2 Theads?</h3> <p>Right now my current solution is to run <code>WorkerThread</code> inside another thread (lets call this new thread <code>MonitorThead</code>). <code>MonitorThread</code> starts <code>WorkerThread</code>, sleeps for 1000ms and then routinely checks if <code>WorkerThread</code> is still alive. If after 15 seconds WorkerThread is still alive, MonitorThread puts WorkerThread to sleep and exits. Is this really the best possible approach?</p> <h2>Summary of Question &amp; Key points</h2> <p>In summary, below is the core question and key restraints associated with the question. Cheers!</p> <p><strong><em>How do I successful kill a java background thread that is stuck in a specific operation?</em></strong></p> <h3>Scenario Restraints:</h3> <ul> <li>No control of having operation pause and check the threads requested state</li> <li>Specific to Blackberry's implementation of Java ME 1.2 and its <a href="http://www.blackberry.com/developers/docs/4.2api/java/lang/Thread.html" rel="nofollow noreferrer">Thread API</a> so no explicit <strong>kill()</strong> method </li> <li>Most concerned about the best practice and how to most safely kill a holding thread.</li> </ul> <hr> <p><strong>Follow Up/Edit</strong><br> Neil Coffey recommended that I simply hold a reference to the connection object and instead call <strong>close()</strong> on that object. I am currently looking into this...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload