Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 213295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:15:55+00:00 2026-05-11T18:15:55+00:00

Question: I’m interested to know the best practice for killing a long standing operation

  • 0

Question: 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 WorkerThread) in Java 1.2.

Scenario

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 (WorkerThread), the thread makes the request and returns the result using a call back.

Scenario Details

Now there exists a situation where at connection time, a data connection exists but then 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.

My Current Solution – 2 Theads?

Right now my current solution is to run WorkerThread inside another thread (lets call this new thread MonitorThead). MonitorThread starts WorkerThread, sleeps for 1000ms and then routinely checks if WorkerThread 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?

Summary of Question & Key points

In summary, below is the core question and key restraints associated with the question. Cheers!

How do I successful kill a java background thread that is stuck in a specific operation?

Scenario Restraints:

  • No control of having operation pause
    and check the threads requested state
  • Specific to Blackberry’s
    implementation of Java ME 1.2 and its
    Thread API so no explicit
    kill() method
  • Most concerned about the best practice and how to
    most safely kill a holding thread.

Follow Up/Edit
Neil Coffey recommended that I simply hold a reference to the connection object and instead call close() on that object. I am currently looking into this…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:15:55+00:00Added an answer on May 11, 2026 at 6:15 pm

    How to kill a Thread is a difficult question. There is no guaranteed way to be able to stop or interrupt a Thread. However, if you take your current architecture and upon timeout, just close the stream (not the Connection), that should cause an I/O Exception to occur on the thread that is stuck in I/O. If it doesn’t cause an IOException, then it should at least cause the read or write to return with EOF.

    Note that closing the Connection doesn’t help, as the JavaDoc says:

    Any open streams will cause the connection to be held open until
    they themselves are closed.

    You have to close the stream that was derived from the Connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question Can I build a image database/library that has an e-commerce style checkout system
Question Is there a way to have a method that will always run anytime
Question: Today I worked with MS Visual Sourcesafe, that is to say Microsoft's Sourcecode
Question: I have a console program that shouldn't be seen. (It resets IIS and
Question: Can anyone please provide a full code example that shows how one does
Question Is there a usable facebook entry point to the Data Storage API that
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Question 1 I want to make IPhone application that uses OpenID for authentication. I
Question as stated in the title.
Question is pretty self explanitory. I want to do a simple find and replace,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.