Can a thread's start() method be called more than once?

Is it legal/well-defined to call a Thread object's start() method after a previous call to start() has completed?
eg.
Thread t = new Thread(public void run() {...});
t.start();
t.join();
t.start(); // will this call fail?

Ok, since no one's going to answer you I will.
Yes. It won't work if you call start() multiple times and it will throw an exception on all subsequent times.
The way I work around it is to put the method in an inner-class and then create a new instance of that iner-class everytime I want to start a new thread.

Similar Messages

  • Method called more than once - and dies with EXC_BAD_ACCESS error

    Hi,
    In my app, I have 4 views with their respective viewControllers. In the appDelegate.m, I provide methods that allows to switch to any of these views. Following is code for switching to the editView:
    -(void) flipToEditView {
    [self populateTheList]; // populate an array
    EditViewController *anEditVC = [[EditViewController alloc] initWithNibName:@"EditView" bundle:nil];
    [self setEditVC:anEditVC];
    [viewController.view removeFromSuperview];
    [self.window addSubview:[editVC view]];
    [anEditVC release]; }
    The view is not switched - and moreover, this method is called more than once; and the app dies with EXCBADACCESS!
    2009-08-23 14:54:40.648 iNotate[2128:20b] Album (before): x= 0 y=20 width=320 height=460
    2009-08-23 14:54:40.653 iNotate[2128:20b] Album (after): x= 0 y= 0 width=320 height=480
    warning: Couldn't find minimal bounds for "_sigtramp" - backtraces may be unreliable
    (gdb) bt
    #0 -[iNotateAppDelegate flipToEditView] (self=0x523690, _cmd=0x9563) at /Users/sam/MY_FILES/iPhone Apps/app/Classes/iNotateAppDelegate.m:116
    #1 0x00008661 in -[FirstView editAction] (self=0x546a30, _cmd=0xac94) at /Users/sam/MY_FILES/iPhone Apps/app/FirstView.m:25
    #2 0x30a4eee6 in -[UIApplication sendAction:to:from:forEvent:] ()
    #3 0x30ab0d36 in -[UIControl sendAction:to:forEvent:] ()
    #4 0x30ab11fe in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
    #5 0x30ab0544 in -[UIControl touchesEnded:withEvent:] ()
    #6 0x30a67917 in -[UIWindow sendEvent:] ()
    #7 0x30a56fff in -[UIApplication sendEvent:] ()
    #8 0x30a561e0 in _UIApplicationHandleEvent ()
    #9 0x31565dea in SendEvent ()
    #10 0x3156840c in PurpleEventTimerCallBack ()
    #11 0x94a713c5 in CFRunLoopRunSpecific ()
    #12 0x94a71aa8 in CFRunLoopRunInMode ()
    #13 0x31566600 in GSEventRunModal ()
    #14 0x315666c5 in GSEventRun ()
    #15 0x30a4eca0 in -[UIApplication _run] ()
    #16 0x30a5a09c in UIApplicationMain ()
    #17 0x000027e8 in main (argc=1, argv=0xbffff068) at /Users/sam/MY_FILES/iPhone Apps/app/main.m:14
    Current language: auto; currently objective-c
    (gdb) continue
    2009-08-23 14:54:55.885 iNotate[2128:20b] >>>>>>>>>>>>>>>>>> populateTheList
    (gdb) bt
    #0 -[iNotateAppDelegate flipToEditView] (self=0x523690, _cmd=0x9563) at /Users/sam/MY_FILES/iPhone Apps/app/Classes/iNotateAppDelegate.m:116
    #1 0x00008661 in -[FirstView editAction] (self=0x5457b0, _cmd=0xac94) at /Users/sam/MY_FILES/iPhone Apps/app/FirstView.m:25
    #2 0x30a4eee6 in -[UIApplication sendAction:to:from:forEvent:] ()
    #3 0x30ab0d36 in -[UIControl sendAction:to:forEvent:] ()
    #4 0x30ab11fe in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
    #5 0x30ab0544 in -[UIControl touchesEnded:withEvent:] ()
    #6 0x30a67917 in -[UIWindow sendEvent:] ()
    #7 0x30a56fff in -[UIApplication sendEvent:] ()
    #8 0x30a561e0 in _UIApplicationHandleEvent ()
    #9 0x31565dea in SendEvent ()
    #10 0x3156840c in PurpleEventTimerCallBack ()
    #11 0x94a713c5 in CFRunLoopRunSpecific ()
    #12 0x94a71aa8 in CFRunLoopRunInMode ()
    #13 0x31566600 in GSEventRunModal ()
    #14 0x315666c5 in GSEventRun ()
    #15 0x30a4eca0 in -[UIApplication _run] ()
    #16 0x30a5a09c in UIApplicationMain ()
    #17 0x000027e8 in main (argc=1, argv=0xbffff068) at /Users/sam/MY_FILES/iPhone Apps/app/main.m:14
    (gdb) continue
    2009-08-23 14:55:22.493 iNotate[2128:20b] >>>>>>>>>>>>>>>>>> populateTheList
    Program received signal: “EXCBADACCESS”.
    (gdb) continue
    What's happening here?
    Sam!

    -(void) flipToEditView {
    [self populateTheList]; // populate an array
    EditViewController *anEditVC = [[EditViewController alloc] initWithNibName:@"EditView" bundle:nil];
    [self setEditVC:anEditVC];
    [viewController.view removeFromSuperview];
    [self.window addSubview:[editVC view]];
    [anEditVC release]; }
    }<---- is this } matched elsewhere?

  • -setFence:count: called more than once per transaction

    I am getting following error, any body have any idea what it is?
    -setFence:count: called more than once per transaction
    Debugger stopped.
    Program exited with status value:101.
    Thanks in Advance
    Ravi

    I am getting the same error...
    T'is usly a m'ry error.
    Use the debugging/testing tools in the latest Xcode to track down suspects, etc.

  • WDDOMODIFYVIEW and WDDOPOSTPROCESSING is called more than once!

    Hello everybody,
    maybe someone can help me. Our WDA application consist of 5 Components. One main and 4 components embedded in it. We instantiate the components in the WDDOINIT of the main component and use them between themselves.
    I suppose that's the reason that the events in the views and componentcontrollers of each component is called so often.
    With a break point in a WDDOMODIFYVIEW an the debugger I find out that the  HANDLE_REQUEST methos from the CL_WDR_CLIENT_ABSTRACT_HTTP  class is startet also more than once.
    1.  if m_ucf is not bound -> yes and  m_request_type = suspend
    2.  if m_ucf is not bound -> initial and  m_request_type = suspend
    3.  if m_ucf is not bound -> initial and  m_request_type = suspend
    4.  if m_ucf is not bound -> initial and  m_request_type = refresh
    Maybe someone has expierence with it an can give a hint or explanations for this.
    I hope so
    Thanks for any answer
    Best regards
    Christian Breitenbach

    hi christian.......
         a wddomodifyview view method will be called even if there is a little change in your view. it will b e called more times than your normal pbo in a dynpro application. the wddoinit will be called only before the view is loaded... but the modify willbe called even for popups nad any event.
    ---regards,
       alex b justin

  • QuickTime DOM Events called more than once?

    I am in the process of writing code in JavaScript that will track the interaction on a embedded QuickTime video.
    function ew_addImage(v) {
    trackImg=new Image(1,1);
    trackImg.src=v;
    function ew_pauseTrk() {
    var imgStr='http://www.sldkfjsldfjk.com/200125/EWTRACKNEW_VINT?ewadid=751801&ewbust='ewbust'&eid=1078554&file=$VIDEO$&bw=56&vlen=3:00&vint=PAUSED';
    ew_addImage(imgStr);
    if (document.addEventListener)
    document.getElementById("mov1").addEventListener("qt_pause", ew_pauseTrk, false);
    Everything works correctly. I am able to see the image being called when I am looking at Wireshark. The problem is when I click pause more than once.. It seems like the QuickTime DOM Events can only be called once.. Is that true?
    Thanks

    -(void) flipToEditView {
    [self populateTheList]; // populate an array
    EditViewController *anEditVC = [[EditViewController alloc] initWithNibName:@"EditView" bundle:nil];
    [self setEditVC:anEditVC];
    [viewController.view removeFromSuperview];
    [self.window addSubview:[editVC view]];
    [anEditVC release]; }
    }<---- is this } matched elsewhere?

  • HT4722 Can Final Cut Pro be purchased and downloaded more than once?

    Can final cut pro be purchased and downloaded on more than one computer?

    This is an excerpt from the FCPX license, available here.
    http://images.apple.com/legal/sla/docs/FinalCutPro.pdf
    2. Permitted License Uses and Restrictions.
    A. Mac App Store License. Subject to the terms and conditions of this License and as permitted by the Mac App Store Product Usage Rules set forth in the App Store Terms and Conditions (http:// www.apple.com/legal/itunes/ww/) (“Usage Rules”), you are granted a limited, non-transferable, non- exclusive license:
    to download, install, use and run for personal, non-commercial use, one (1) copy of the Apple Software directly on each Apple-branded computer running OS X (“Mac Computer”) that you own or control; and
    (ii) if you are a commercial enterprise or educational institution, to download, install, use and run one (1) copy of the Apple Software for use either: (a) by a single individual on each of the Mac Computer(s) that you own or control, or (b) by multiple individuals on a single shared Mac
    Computer that you own or control. For example, a single employee may use the Apple Software on both the employee’s desktop Mac Computer and laptop Mac Computer, or multiple students may serially use the Apple Software on a single Mac Computer located at a resource center or library.

  • Function module In Update Task is called more than once

    Hi experts!!
    I had a requirement to Create a Customer ( i will call it B) when another Customer (A)  is created (ON SAVE).
    I used a Badi to implement the requirement, and inside my Badi i have 2 Function Calls in Update Task.
    The first one to create Customer B and the second one to send Customer's B data to another System.
    Even though the second function call is inside an IF-ENDIF condition ( so that only Customer's B data are sent) the function is called twice sending the same data. My guess is that since the First Function saves the Customer to the database, that is the reason why the second Function is called twice.
    Is there any way i can control how many times a Function In Update Task is called????
    Please help!!
    Thank you in advance!!

    Hi BreakPoint & thank you for your reply!!
    I tried your suggestion but even if i fill the flag during the first call the function is called twice. Looks like during the second database commit the function is called with the correct conditions met but twice.
    Also while debugging it looks like it is only called once. It s very strange!
    Any other ideas???

  • Can I download stuff I buy on iTunes more than once now? (because of iCloud)

    Can I go to the "Purchased" section of Itunes on the iPad as a way of downloading stuff I buy multiple times, and not need to worry about making backup copies any time I remove something from my device?  Or am I only able to download stuff once per device?

    Thanks.
    There's not a limit on the number of times, is there?
    I don't think so, as I tried it briefly with a TV show I bought a long time ago, but I haven't tried it with music or anything.

  • Beginner method aparently runs more than once

    Ok, first of all I own up to this being my school homework. I am almost finished but I have the unexpected result of my player being hit twice as predicted by happy_hippo in prior post. Here are the two classes. Basically the method fired_at() in Player seems to be running twice?
    Any help is appreciated...
    public class GameEngine
    public static void main( String args[] )
    Player myPlayer = new Player();
    myPlayer.Player("Michael Stramel");
    if (myPlayer.fired_at() == 100)
         System.out.printf("%s was not hit and has 100 health.", myPlayer.getplayerName());
    else
         System.out.printf("%s was hit and has %.2f health.", myPlayer.getplayerName(), myPlayer.fired_at());
    import java.util.Random;
    public class Player
         private String playerName;  //name of player
         private float playerHealth;  //health of player
    public void Player ( String name )
         playerName = name;
         playerHealth = 100;
    public void setplayerName( String name )  //method to set the player name
         playerName = name; // store the player name
         } //end method setplayerName
    //public void setplayerHealth( String name )  //method to set the player health
    //     playerName = name; // store the player health
    //     } //end method setplayerHealth
    public String getplayerName()  //method to retrieve the player name
         return playerName;
         }//end method getplayerName
    //public float getplayerHealth()  //method to retrieve the player health
    //     return playerHealth;
    //     }//end method getplayerHealth
    public float fired_at()
         Random randomHit = new Random();
         boolean x = randomHit.nextBoolean();
              if (playerHealth >= 20)                                    //Random boolean here   
                   {                                                            //If boolean = true & if player
                   //if (x == true)                                             //health >= 20,
                   //     {                                                       //(playerHealth = playerHealth - 20)
                   playerHealth = (playerHealth - 20);
              //else
                   //playerHealth = 0;
              return playerHealth;
    }

    This is (sort of) how I would rewrite your code, I have tried to keep your original variable names where possible.
    I would however consider renaming:-
    fired_at() -> fireAt()
    getplayerName() -> getPlayerName() -(or possibly)-> getName()
    getplayerHealth() -> getPlayerHealth() -(or possibly)-> getHealth()
    setplayerName() -> see convention above
    setplayerHealth() -> see convention above
    be consistent!!! fireAt() versus getplayerName()
    And I think you need to comment A LOT LESS! Why label the end of a method? I don't think there is any need to label get/set methods (although you would for Javadoc)
    Trick:
    public Player(String playerName)
       //assigns the local variable (passed in) to the class variable
       this.playerName = playerName; 
    var = var - x;
    //is equivalent to
    var -= x;
    public class GameEngine
       public static void main( String args[] )
          Player myPlayer = new Player("Michael Stramel");
          myPlayer.fired_at();
          if (myPlayer.getplayerHealth() == 100)
             System.out.printf("%s was not hit and has 100 health.", myPlayer.getplayerName());
          else
             System.out.printf("%s was hit and has %.2f health.", myPlayer.getplayerName(), myPlayer.getplayerHealth());
    import java.util.Random;
    public class Player
       private Random rnd;
       private String playerName;
       private int playerHealth;
       //NB: removed void, this is now a constructor
       public void Player ( String name )
          playerName = name;
          playerHealth = 100;
          rnd = new Random();
    // NB: Do you need this method? Do you really want to be able to change
    // the name of a player once they have been created??
    // public void setplayerName( String name )
    //    playerName = name;
    //    //again, I would use the this. trick (above)
       public String getplayerName()
          return playerName;
       public int getplayerHealth()
          return playerHealth;
       //note: void, not int (or float)
       public void fired_at()
          if (playerHealth >= 20)
             if (rnd.nextBoolean())
                playerHealth -= 20;
          else
             playerHealth = 0;
    }

  • Can you restore a time machine back-up more than once?

    Hi,
    About a week ago I tried restoring an old time machine backup to check that it worked - and it did. I now want to restore that same backup again. It's still there on the external drive that it was backed up onto, but no longer has a time stamp associated with it, and it no longer allows me o restore it. Any help would be appreciate d.

    I was not aware that such a limitation existed.  Try this:  (disable Time machine temporarily
    Click on the Time Macine HDD, and open ''Backups. backupdb' folder.  You then might see another folder with you name on it.  Open that folder which should show you a series of folders with a series of dates.  See EX.
    Select the folder with the date where the data that you want to retrieve resides.  Open that folder and keep opening folders until you get to the item you wish to restore.  Drag the item to your desk top.
    Ciao.

  • Calling thread.start() more than once concurrently

    Hi, I got a simple doubt that may feel awkward or absurd to people who are well versed in the java threading concepts. I just thought of it and as I couldn't get an easy answer I am posting this.
    Consider a class that implements the runnable interface. The run() method of the class is implemented with just a System.out.println(). If I make an instance of this class, say 't' in the main method and calling t.start() susequently twice or thrice; an illegal ThreadStateException will be thrown. The code snippet is as follows:
    ThreadTest t = new ThreadTest();
    t.start();
    t.start();
    It is understood that state of the thread object is changed to run state and so, if it is again started, it must be thrown. So if I put a Thread.sleep() inbetween these two subsequent calls assuming that the main method thread will be sleeping. So there is sufficient time for the first thread to terminate and then only the second will start - still the same exception is being thrown. I tried putting the synchronized qualifier for run too, still no effect - the same only happening. Why the java thread object is made in such a way that once the thread changes it state from Runnable to Running and then finally to dead state, it can be restated back to Runnable state, such that the start() method can be called again. Is it possible or not? Please post your comments.

    As ejp says you can't start a thread more than once - even if it has already terminated after the first start.
    By making threads a one-shot it simplifies reasoning about them: you don't have to wonder whether a second start() will work or not, depending on whether the thread has completed its first "incarnation". It also makes it easier to ensure thread resources are reclaimed. It also avoids semantic issues like whether anything about the thread is "carried over" across incarnations.
    This might seem a limitation but there are many ways around it - simply don't let the thread terminate. Whatever control structure you would enforce by re-starting the thread can be emulated without letting the thread terminate in between "executions".

  • Methods that return more than one object.

    Hello everyone,
    I don't know if this has ever been proposed or if there's an actual solution to this in any programming language. I just think it would be very interesting and would like to see it someday.
    This is the thing: why isn't it possible for a method to return more than one object. They can receive as many parameters as wanted (I don't know if there's a limit), but they can return only 1 object. So, if you need to return more than one, you have to use an auxiliary class...
    public class Person {
       private String name;
       private String lastName;
       public Person(String name, String lastName) {
          this.name = name;
          this.lastName= lastName;
       public String getName() {
           return name;
       public String getLastName() {
           return lastName;
    }So if you want to get the name of somebody you have to do this, assuming "person" is an instance of the object Person:
    String name = person.getName();And you need a whole new method (getLastName) for getting the person's last name:
    String lastName = person.getLastName();Anyway, what if we were able to have just one method that would return both. My idea is as follows:
    public class Person {
       private String name;
       private String lastName;
       public Person(String name, String lastName) {
          this.name = name;
          this.lastName= lastName;
       public String name, String lastName getName() {
           return this.name as name;
           return this.lastName as lastName;
    }And you would be able to do something like:
    String name = person.getName().name;and for the last name you would use the same method:
    String lastName = person.getName().lastName;It may not seem like a big deal in this example, but as things get more complicated simplicity becomes very useful.
    Imagine for example that you were trying to get information from a database with a very complex query. If you only need to return 1 column you have no problem, since your object can be an array of Strings (or whatever type is necessary). But if you need to retrieve all columns, you have three options:
    - Create 1 method per column --> Not so good idea since you're duplicating code (the query).
    - Create and auxiliary object to store the information --> Maybe you won't ever use that class again. So, too much code.
    - Concatenate the results and then parse them where you get them. --> Too much work.
    What do you think of my idea? Very simple, very straight-forward.
    I think it should be native to the language and Java seems like a great option to implement it in the future.
    Please leave your comments.
    Juan Carlos García Naranjo

    It's pretty simple. In OO, a method should do one thing. If that thing is to produce an object that contains multiple values as part of its state, and that object makes sense as an entity in its own right in the problem domain--as opposed to just being a way to wrap up multiple values that the programmer finds it convenient to return together--then great, define the class as such and return an instance. But if you're returning multiple values that have nothing to do with each other outside of the fact that it's convenient to return them together, then your method is probably doing too much and should be refactored.
    As for the "if it increases productivity, why not add it?" argument, there are lots of things that would "increase productivity" or have some benefit or other, but it's not worth having them in the language because the value they add is so small as to no be worth the increase in complexity, risk, etc. MI of implementation is one great example of something that a lot of people want because it's convenient, but that has real, valid utility only in very rare cases. This feature is another one--at least in the domain that Java is targetting, AFAICT.

  • How can I add the same song more than once?

    how can I add the same song to my ipod shuffle more than once?

    Thanks. I tested it, and found that I can create a bookmark in FolderA, and them manually copy it to FolderB, FolderC, and FolderD.
    Once that is done, I tried the old method of "Bookmarks" --> "Bookmark This Page" and added it to FolderE. When I did that, it deleted the copy in FolderD but left the other three alone!
    This is fine with me. I personally think this is a bug, because I don't think that Firefox should ever delete a bookmark without asking me (or at least, informing me). But now that I understand the algorithm, I can work around it. Thanks!

  • Can I have my Adobe X Pro on more than one computer?

    Can I have my Adobe X Pro on more than one computer?

    Well, yes, but I think there's an important point to make; I'm surprised you talk about "downloading it again". That suggests you didn't make an archive copy of the installer you downloaded for the first computer.
    It is VITAL to archive a copy of what you download for software you buy. That doesn't mean just leave the download on disk, because you will need it if that disk fails or computer is dropped on the floor. We constantly see people that didn't get a copy of their old software, and now it is no longer available for download, leaving them just stuck!
    So, please, save a copy on CD or DVD. Also, write the serial number on the disk, and any qualifying number if it was an upgrade. I'd hate you to be another statistic in the "how do I reinstall my old software" threads.

  • Error: An attribute cannot appear more than once in the same start tag

    Hi Everyone,
    when i run the page sometimes it works fine but sometimes it throws Compilation Error as below.
    "Error(502,1224): file:/C:/Jdeveloper/jdevhome/jdev/myhtml/OA_HTML/fwk/t/Session_2055663493/region1.uix<Line 502, Column 1224>: XML-20124: (Fatal Error) An attribute cannot appear more than once in the same start tag."
    And i delete the particular file from the path and run the page so this time it works fine.
    But later after sometime i get the same error but the session number will be changed, then again i need to delete it and run.
    What can be the permanent solution for this issue?
    Plz let me know any suggetions.
    Thanks.

    Seems like the mdl file is corrupted or was not generated correctly.
    Can you try to create the mdl file again and then try the import ?
    If it doesn't work then try contacting Oracle Support.

Maybe you are looking for

  • DS 6.0 Proxy Configuration

    I am having some problems configuring the DSEE 6.0 Proxy Server. It seems like it should be fairly straightforward and maybe I am missing something obvious. I create the Proxy Server instance, then created a data source to my Directory Instance, thro

  • Help to set up data in tables

    Hi, i have to tables itab1 and itab2 what is the best way to set up the data like i wont to itab3 . Regards i give example: itab1 : 20071 20072 20073 20074 20081 itab2: 20061 20062 20063 20064 20071 i wont to set data in itab3 like this: itab3 20071

  • How do I delete the contents of pages waiting in the queue to be loaded?

    While attempt to edit a table on the last pages of my document, the InDesign program crashed. I attempted this several times, including just deleting a row at a time, but run into the same problem. Since it was the last pages of the document (book),

  • Use Tables for Image Layout?

    I'm in the process of learning HTML and putting together some sites. The book I'm reading is several years old but is very thorough. It suggests taking slices from a page mockup in PS/IR, optimizing (saving only the images, not code), then re-assembl

  • Business Rules and Business Intelligence in Java CAPS 6

    Dear All, I have two doubts. 1. Is there any way to add a Business Rule component and write Business rules in Java CAPS 6? As you may know, this is possible through eInsight in JCAPS 5.1.2. Is this feature readily available in Java CAPS 6? If yes, ca