Destorying a thread by name?

Is there any way destroy a thread by name? For example I name a thread musicthread and then call musicthread.destroy().

ah could be...but still, SUN's own recommendations say that if you want to kill a thread, the way to do it is via a boolean at the top of your run() method.
As you pointed out, thread.stop() leaves your threads internal data structures in disarray and causes deadlocks which is why they say don't use stop.
As to citing the exact words, I have no idea what the link was where I read it. But it was on THIS site (not some third party site)...so maybe in the tutorial on Threads or in one of their weekly question and answer tutorials.

Similar Messages

  • Is it "legal" to change a thread's name in Weblogic 8.1/9.2/10.3?

    Hi,
    A very simple question that I couldn't find an answer to:
    Can I change a thread name in a J2EE / Java EE environment? The executing code is an EJB. Will I cause mayham if I change the thread's name to something else?
    I need to know this mainly for Weblogic 8.1 / Java 1.4, since there is no such thing as a "unique thread id" in Java 1.4, so I must generate my own unique thread id and rename the thread. For Java 1.5 and above, there is already a unique thread id.
    Thanks for the help.

    This has been raised as an Enhancement request and has not yet been implemented.
    Bug 6566830 - 8-522961581 - would like ability to customize year description
    This would be useful when the fiscal year is not the same as the calendar year. Example of customization:
    Sep 2006 becomes Sep FY 2006/2007
    HTH-
    Jasmine.

  • Accessing a Thread by name?

    Hello everyone, I have a question about thread programming. I have several threads running and the are all named. I'm wondering if there is a way from my main code to access a specific thread by name? for example, my main program wants to call a method in "ThreadB"?
    I'm programming a chat type application and I need to be able to add a client to a host thread ...... here's an example
    packetType = recvData.getInt();
    if(packetType == JOIN_HOST)
         // This is the name of the thread the client wants to
         // connect to.
          String hostName = recvData.getString();
         // Here is where I need to access a specific thread based on the host
    // the client wants to connect to.   Any Ideas?
    }I know this question seems brief but if anyone can help I would be very thankful....
    Thanks,
    Mike

    david: not sure if I am, let me explain a little more. I am writing a chat program and I have a couple different classes. I have a separate host program that a host user logs in with. The server will spawn a new thread for each host that is logged in. These host threads are what i am talking about. A client will log in and be shown a window with a list of the online host users. I have the client selecting a host user and sending the request to the server...... here is where my problem is. I need to, based on the name the client send, connect the client with the desired host. So, If I make a method in the host class is it accessable outside the thread?
    If not, how can I add a client object to a running host thread?
    Sorry if I'm not explaining this correctly.
    Mike

  • What role does thread with name of form pool-n-thread-m play?

    Hello
    JE version 5.0.97.
    Looking at the threads created by a node in the master role, I see only one thread without a descriptive name. It has the executor default of pool-n-thread-m.
    What role does this thread take?  I ask out of curiosity.
    "MASTER node1(1)" daemon prio=6 tid=0x0000000008d07800 nid=0x26cc waiting on condition [0x000000000a52f000]
    "Feeder Output for node2" daemon prio=6 tid=0x0000000009a9b800 nid=0x1e20 waiting on condition [0x000000000a82f000]
    "Feeder Input for node2" daemon prio=6 tid=0x0000000009a1d000 nid=0x25cc runnable [0x000000000a72f000]
    "MASTER node1(1)" daemon prio=6 tid=0x0000000008d07800 nid=0x26cc waiting on condition [0x000000000a52f000]
    "Acceptor Thread node1" daemon prio=6 tid=0x0000000008aed000 nid=0x2248 waiting on condition [0x000000000a42f000]
    "Learner Thread node1" daemon prio=6 tid=0x0000000008ad1000 nid=0x2058 waiting on condition [0x000000000a32f000]
    "ServiceDispatcher-localhost:5551" daemon prio=6 tid=0x0000000008a8a800 nid=0x2508 runnable [0x00000000097ff000]
    "Checkpointer" daemon prio=6 tid=0x0000000008a8a000 nid=0x9a0 in Object.wait() [0x00000000096ff000]
    "Cleaner-1" daemon prio=6 tid=0x0000000008a0c000 nid=0x16cc in Object.wait() [0x00000000095ff000]
    "INCompressor" daemon prio=6 tid=0x0000000008b4e000 nid=0x2560 in Object.wait() [0x00000000094ff000]
    "pool-1-thread-1" prio=6 tid=0x00000000070ff800 nid=0x222c waiting on condition [0x000000000a62f000]
    Could you consider naming this thread in a future release? It would assist with problem diagnosis by allowing users to know with certainty which threads belong to JE.
    Kind regards, Keith Wall.

    Keith,
    These threads are part of the thread pool that watches for incoming network connection requests, and help establish new sockets. We should certainly name them, and will do so in the next release. I think they'll be named ServiceDispatcher <nodeName>.
    Regards,
    Linda

  • What is the correct way to destory a Thread?

    Just wondering what is the correct way to destroy a thread? I am currently using the stop() method, but i noticed that it has been depreciated (along with other methods used to destroy a thread) when i looked at the thread documentation. Since this is so, then how can one correctly destroy a thread? Thanks in advance for the help.

    There is an awful lot of bad advice in this thread about what null does. Please in future check on your own with working code before offering up misguided and very wrong advice. Particularly when your advice contradicts that previously given.
    Please compile and run the following
    public class Test implements Runnable{
      public static void main(String args[])throws Exception{
        Test test = new Test();
        Thread t= new Thread(test);
        t.start();
        // have delay wait a few seconds to demonstrate
        Thread.sleep(3000);
        System.out.println("Setting reference to thread to null");
        t = null; // what does this do?
        // jack all
        System.out.println("Exiting main");
      public void run(){
        while(true){
          System.out.println("Hello from test thread!");
          try{ Thread.sleep(750); }catch(InterruptedException iDontCareAboutThis){}
    }This will output the following
    C:\>java Test
    Hello from test thread!
    Hello from test thread!
    Hello from test thread!
    Hello from test thread!
    Setting reference to thread to null
    Exiting main
    Hello from test thread!
    Hello from test thread!
    Hello from test thread!
    Hello from test thread!
    Hello from test thread!
    Hello from test thread!And continues on endlessly. Setting the reference to null is NOT an answer to this problem.

  • New name to 'main' thread

    Hi All,
    I tried to change the name of the main thread with the following code:
    class TT{
    static public void main(String [] args){
    MyRunnable r = new MyRunnable();
    Thread.currentThread().setName("newmain"); //new name given to main thread
    System.out.println("Thread :"+Thread.currentThread().getName());
    Thread t1 = new Thread(r,"a");
    Thread t2= new Thread(r,"b");
    Thread t3 = new Thread(r,"c");
    t1.start();
    t2.start();
    t3.start();
    class MyRunnable implements Runnable{
    public void run(){
    System.out.println("Current Thread is"+Thread.currentThread());
    try{
    Thread.sleep(100);} catch(InterruptedException e){}
    }The output show something like this ->
    Thread :*newmain*
    Current Thread isThread[a,5,*main*]
    Current Thread isThread[b,5,*main*]
    Current Thread isThread[c,5,*main*]
    What I am trying to ask here is: In the last three lines newmain_ should have appeared in place of main_ . Because I changed the name of the main() thread. Am I right??

    class TT{
    static public void main(String [] args){
    MyRunnable r = new MyRunnable();
    Thread.currentThread().setName("newmain"); //new name given to main thread
    System.out.println("Thread :"+Thread.currentThread().getName());
    Thread t1 = new Thread(r,"a");
    Thread t2= new Thread(r,"b");
    Thread t3 = new Thread(r,"c");
    t1.start();
    t2.start();
    t3.start();
    class MyRunnable implements Runnable{
    public void run(){
    System.out.println("Current Thread is"+Thread.currentThread());
    try{
    Thread.sleep(100);} catch(InterruptedException e){}
    }Hi..
    You have created 3 different threads from main thread with name a,b and c. In run() you are printing the current thread not name so the result. If you print name, you will get the name as a,b,c not newmain...

  • Problem with ioinning multiple Threads

    Hi,
    I have multiple sub Threads T1, T2, T3.... started by main Thread T. After starting each sub Thread, I stored them in the HashMap. When finish starting all Threads, I want to join each sub Thread to my main Thread.
    The problem is when T3 join with T, it hanged forever! Here is my code:
    class MyThread extends Thread
    private name;
    MyThread(String tName)
    name = tName;
    public void run()
    // doing something....
    public HashMap startThreads()
    HashMap tList = new HashMap();
    for (int i=0; i<5; ++i)
    String tName = "Thread" + i;
    MyThread myT = new MyThread(tName);
    myT.start();
    tList.put(tName, myT);
    public void joinThreads(HashMap tList)
    Iterator iter = tList.values().iterator();
    while (iter.hasNext())
    Thread activeThread = (Thread)iter.next();
    if (activeThread.isAlive()) {
    System.out.println("Join alive thread " + activeThread.tName);
    activeThread.join();
    In my method:
    ... doing s/t
    HashMap tMap = startThreads();
    joinThreads(tMap);
    ... doing s/t else (never excecuted!!!)
    My purpose is staring multi Threads at the same time and executing some code after they all die.
    If I join my sub Thread right after creating it, then the other sub Thread couldn't started until subThread 1 dies!
    If I don't join the sub Thread but remove it from the thread Map when it's not alive then my code executed perfectly. I want to apply join method with my mutiple Threads, how ????
    Could some one give me a hint? Thanks.

    Hi,
    What I don't understand here is why the main Thread
    does not join all the sub Threads ?If you're getting a ConcurrentModificationException while iterating the list of threads, then that's why.
    Why main Thread
    has to wait for sub Thread 1 to finish before joinning
    next sub Threads?It has to join all of the threads. That means it has to wait for all of them to finish. In order to wait for all of the threads it has to wait for the first thread.
    I'm 100% sure that my sub Threads in
    the threadList are valid and alive since I already
    veriffied with other methods.I don't see what that has to do with your problem.
    I already set my joinThreads method as synchronized,
    how come I still have ConcurrentModificationException?Because the list was modified concurrently.
    How can I fix this error?Stop modifying the list concurrently. You haven't posted all of the relevant code, so I can't offer any clues about how to do that.

  • How to append msg from second thread to main GUI thread?

    I am facing a problem which I cannot seem to solve.
    It involves Swing and threads. I have a main GUI running on swing. And it retrieves database information and displays it. On the same GUI I have a JTextArea box which I need another thread to update as and when that second thread recieves message via a multicast socket.
    I managed to create a runnable class of the second thread and successfully ran the second thread with the main thread in tandem. However when I use
    display.append(msgreceived);
    I get a nullPointerException. It works fine when i use System.out.println(msgreceived);.
    What should I have done instead?

    Here are part of the codes for my admin module.
    public class Admin extends JFrame implements ActionListener {
    //declares all the global variables
    private JTextArea display;
    public Admin() {
    super("BX Online - Admin Module");
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    AdminGUI();
    AdminGUI() {
    contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    JPanel newsbox = new JPanel();
    display = new JTextArea(2, 40);
    display.setEditable(false);
    newsbox.add(display);
    contentPane.add(newsbox);
    contentPane.add(tabpaneO);
    setBounds(70, 50, 300, 500);
    pack();
    setVisible(true);
    // all the methods activated by buttons goes here
    static public void main(String[] argv) {
    Admin a = new Admin();
    News b = new News("test");
    The following are part of the codes for my runnable class.
    public class News implements Runnable {
    protected boolean again = true;
    private String name, recieve; //the global variables
    private Thread t;
    public JTextArea display;
    public BXnews(String threadname) {
    name = threadname;
    t = new Thread(this, name);
    System.out.println("New Thread: " + t); //visual check to make sure thread is started.
    t.start();
    private void msg() {
    String recieve = ("testing");
    System.out.println(recieve);
    display.append(recieve);
    public void run() {
    while (again) //creates a loop so thread does not close
    {msg();}
    Well thats abt it. I'm not sure if you can compile this but basically the part I left out was the setup link for the News class which I don't see the need to add as what I primarily intend is for the message testing in News class to appear in Admin class thread in JTextArea "display".

  • F-58 Error. vendor name printed but not Alternative payee

    Dear group members
    _Vendor name printed but not the name i entered in Individual set_
    I followed Thread vendor name changed at the time of taking cheque printing
    I made the below Transaction
    1. I made the changes in vendor master under the head Payment transaction tab, in Alternative payer in document i selected check box of Individual entries
    2. Posted in FB60 vendor invoice under payment tab check box Individual payee is selected, i entered alternative name so that check is printed in this name
    3.In payment F-58 post & print i selected open item for payment after simulation i saved .The check is printed as per the
    Name in Vendor master data but not the name i entered in Individ.setin fb60
    I am not able to make to make payment, guide me 
    Your advice on this will be highly appreciated
    Regards
    shamulheq

    Hi  MUKTAKUMARI  
    I entered the bank details in the individual payee while entering FB60, the name coming in indiviid .set
    In F-58 I made simulation Pk 50 QNB -Checks Payable & PK 25 vendor name, when i double click on the 2nd line item i found the name what mentioned in the Individ.set
    I saved the transaction but the check was printed in the name of vendor master but not in the name i entered in indiviid set
    Help me out to get the  check printed in the individ set
    Regards
    shamulheq

  • IMessage contact names issue

    When receiving a notifcation from iMessage, the contact name does not appear. The notification only shows the Apple ID or the phone number of the person messaging me. However, in the iMessage app itself, the contact names correctly appear in the left side bar. This issue only occurs when receing a notifcation.
    In addition, when viewing messages in a group thread, contact names do not appear besides individaul messages. Thus, it is impossible to distingush who sent what message in a group thread. Still, the contact names of all those in the group message correctly appears in the left side bar.
    The contacts app correctly stores the contact information for the people who are messaging me, so it is not an issue with me not having the correct contact information. I'm unsure of what casued this issue, since it appered somewhat spontaneously after correctly working for over a year.

    Hi,
    In the View Menu > Messages > Show as Pictures and Names
    If the Buddy lists you have are not on show or are not the highlighted window AND the Messages window itself is not the highlighted/focused window then some of this Menu woill be greyed out.
    In this Picture the main Messages window is the focused one and therefore the Buddy List related ones are greyed out.
    8:50 pm      Thursday; March 13, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • How to run the Thread twice

    Why the program only can print from 0 to 9 once, not twice?
    Thank you!
    Here is my program
    class TestThread extends Thread
         String name;
         public void run(){
              for(int i=0;i<10;i++){
              System.out.println(i);
              try{
              sleep((long)(Math.random()*1000));
              }catch(Exception e){
                   System.out.println(e.toString());
         public static void main(String[] args){
              TestThread t = new TestThread();
              TestThread t1 = new TestThread();
              t.start();
              try{
              t.join();
              }catch(Exception e){
              t.start();

    Why the program only can print from 0 to 9 once, not
    twice?
    Thank you!
    Here is my programBecause the run() method returns after printing the numbers once and sleeping a random amount of time. When you return from the run() method, the thread ends.
    Threads cannot be restarted, i.e., if a thread has ended you cannot call start() on it again. If you want to do that, just create a new object and call start() on it.
    Maybe you want a loop in your run() method:
    public void run() {
      while (true) {   // Keep doing this forever!
        for(int i=0;i<10;i++) {
          System.out.println(i);
          try {
            sleep((long)(Math.random()*1000));
          catch(Exception e) {
            System.out.println(e.toString());
    }Jesper

  • Can't name group chat in iOS 8

    Anyone else not seeing an option to name a group chat? I've brought up the details and swiped down and am not being given an option to name the chat. Does everyone in the group chat have to be an iPhone user?

    Hello mfaulconumw,
    Thanks for using Apple Support Communities.
    To give a group message thread a name please do the following:
    Give a group a name. While viewing the conversation, tap Details, then drag down and enter the name in the Subject line.
    Send and receive messages
    Take care,
    Alex H.

  • [Swing] JTable & Oracle DB: SQL Query for Column Names Change

    Hello,
    I apologise for the 'stupid' thread subject name.
    Now i have a JTable wich i fill with rows from an Oracle DB.
    The query is something like this: "SELECT location_id, location_name FROM locations*bold*", and in the table i will have the columns names LOCATION_ID & LOCATION_NAME.
    I want to change this query like: "SELECT location_id "Location ID", location_name "Location Name" FROM locations".
    The only problem is that i CAN NOT insert "" inside ""
    So if anyone know how to fix this 'problem' please share that with me.
    Thank you,
    B.

    found it.. \" \"
    :)

  • Table name for GPARN

    HI Everone,
    I need database table name for GPARN field, I Appreciate if any one can share

    Hi Everyone,
    I got  the answer below and i am closing the thread
    table name WYT3, Field PARNR which i am looking for,
    Thanks for Everybody
    Bharath

  • Why not change the  Macintosh HD to a shorter name.

    I have a friend that picked up a Mac mini with OS X 10.5.8 and one for the first things
    I noticed was the previous owner had changed the name of the single drive from Macintosh HD
    to a shorter name
    I recall reading somewhere that it is not a good idea to change the name of the primary
    hard drive from Macintosh HD and I cannot remember why.
    Can someone point me to a document that describes why the primary hard drive should not be renamed?

    {Usually the problem occurs when a user changes the Short Name of the
    computer where it affects how it is then seen in a network, and does this
    improperly so the computer can't be networked until this issue is fixed.}
    • Mac OS X: How to change user short name or home directory name:
    http://support.apple.com/kb/ht1428
    • Mac OS X (10.4) Help: What's my computer's name and address?
    http://docs.info.apple.com/article.html?path=Mac/10.4/en/mh632.html
    • How do I change the Owner's Name on my Mac?
    http://www.askdavetaylor.com/howto_change_owners_name_applemac.html
    And if you change the Short Name (account user, etc) then KeyChain
    access and other items may well be a real problem to weed out & fix.
    Note the comments, after the basic info in this thread:
    • Changing Names - Root - Mac Gems - MacWorld:
    http://www.macworld.com/article/41481/2004/12/changeshortname.html
    Or, if a user changes the name of their User Account, improperly, then the
    account won't match the password and other issues will result; unless it
    is fixed or the problem of changing the name incorrectly in the first place
    is avoided; since there is a proper way to change the short name of the
    computer (not that on the icon of the hard disk drive, btw) and a correct
    way, a process, to change the user account name.
    It is not advised to change the User name on an account or that of the
    Computer's name where it is seen on a network. That aside, the name
    change of the computer's Hard Disk Drive, at the icon on the desktop,
    can be avoided by using Dock preferences to Hide the HDD so it will
    not appear on the desktop at all. (Kids in schools change the HDD icon's
    name frequently, when it is available and the computer not set up to
    work under the Parental Controls or lower user account privilege access.)
    +You can change the name of the Hard Disk Drive and that won't make+
    +much difference; except in those cases where you have an Alias of the+
    +original name, since it would no longer activate access to the Mac HD.+
    I got over the urge to change the HDD name some time ago. However
    if you partition the original hard disk drive so you have two icons on the
    Desktop, you could have fair reason to change the names if you like.
    (Just remember, if you make a clone, or do any complete computer drive
    backup to some external device, the name change could affect the result.)
    If you have an Intel-based Mac running Windows, you may have a different
    matter in re-naming the hard disk drive; since Windows may require another
    avenue into the means to rename that drive. And then, that may be a problem.
    *You can change the Mac HD to any name.* In previous Mac OS (pre-x) versions
    it was also common for users to change the hard drive icon to some other one,
    and if they'd named the computer (a monster name, for example) a new image
    for the icon could easily be applied through a copy-paste. In fact, that may still
    be something one may be able to do, through a different agency in OS X.
    And, when installing an all-new OS X, you can also change the name of the Mac HD
    in Disk Utility, since the name is blank after choosing a partition scheme & reformat.
    The real issue revolve around changing the computer's short name, and changing
    the user's account name(s) since this is where problems begin that are harder to fix.
    If the rules are followed in regard to these two, going into the situation, problems
    are more readily avoided. I just don't change those things, since I'm too busy.
    Good luck & happy computing!
    { edited 2x }

Maybe you are looking for