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 5966149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:45:14+00:00 2026-05-22T19:45:14+00:00

I have a question regarding threading in Java. In my code, … client.doSth(); //

  • 0

I have a question regarding threading in Java. In my code,

...
client.doSth();
// now need to get hold of the thread that is initiated by 'client'
(get a reference to the 'client' thread)
// now kills it
(kills the 'client' thread)
...

So what I would like to know is: in the first brackets, how do I programmatically get hold of a reference to the ‘client’ thread (NOT the main thread the program is running on), and in the second brackets, how do I properly kill it, i.e. without using the depreciated stop() method.

Many thanks.

  • 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-22T19:45:15+00:00Added an answer on May 22, 2026 at 7:45 pm

    Edit:
    after rereading the question I am not sure any more if you have access to the client code. If you do, well you can revise it and not even use thread but java.util.concurrent.ExecutorService or the likes.. yet

    Since the code is not your own… you are on your own to stop it.

    ThreadGroup class is designed for. Managing partial programs or modules is not exactly easy and usually it takes some already established framework. Ensuring some 3rd party code will behave and be nice and all it’s not always possible. It should include context classloader and what not but here is a skimmed version of how it’s done.

    Still there might be something you can do to break the bone of the intruder. Assuming stop()/close(), etc has been used, some tricks like ThreadDeath during logging and so on.

    ThreadGroup g=new ThreadGroup("client X group");
    
    Runnable r=new Runnable(){
    public void run(){
      client.doSmth();//assuming a new thread is started...
    }
    }
    Thread t= new Thread(g, r, "clientStarter");
    t.start();
    
     //stopping, last resort code, it's usually more complicated than just thread.stop, though
    
    //now you can enumerate threads of the ThreadGroup
    synchronized(g){//sync ensures no more threads will be created, use it w/ extreme caution
      Thread[] threads = new Thread[g.activeCount()];
      for(Thread thread:threads){
        if(thread==null) break;
        thread.stop();//
      //cannot join in sync of ThreadGroup, do not use it here
        }
      }
    

    Good luck!

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

Sidebar

Related Questions

Following on from my recent question regarding parsing XML files in Java I have
Right now i am trying to learn more about java threading, and i have
I have a quick question regarding a database that I am designing and making
I have a question regarding the following code: abstract class a { public static
I have a question regarding using intptr_t vs. long int . I've observed that
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a question regarding handling errors in a J2EE application. Our current application
I'm writing a small webapp in Grails and I have the following question regarding
I have a question about best practices regarding how one should approach storing complex

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.