How to run a thread for second time ?

I have a written a ThreadPool, but I found that basically a thread is not running for the second time. i.e First i call run() method and call stop(). If i call again run() method for the same thread, it is not running. What should I do, If i want to run the thread for the second time ?
class NewThread implements Runnable {
String name;
NewThread(String a) {
name=a;
public void run() {
try{
for(int i=0;i<5;i++) {
System.out.println("Thread :" + name + " #" +i);
Thread.sleep(5);
catch (Exception e) {
e.printStackTrace();
class threadRunnableTest {
public static void main (String args[]) {
Runnable runnable=new NewThread("BaSkAr");
Thread thread = new Thread(runnable);
try{
System.out.println("First Thread is starting !!!");
thread.start();
Thread.sleep(2000);
System.out.println("First Thread it to be stopped!!");
thread.stop();
System.out.println("Second Thread is starting !!!");
thread.start();
Thread.sleep(2000);
System.out.println("Second Thread it to be stopped!!");
thread.stop();
catch (Exception e) {
e.printStackTrace();

baskark wrote:
I have a written a ThreadPool, but I found that basically a thread is not running for the second time. i.e First i call run() method and call stop(). If i call again run() method for the same thread, it is not running. What should I do, If i want to run the thread for the second time ?
class NewThread implements Runnable {
String name;
NewThread(String a) {
name=a;
public void run() {
try{
for(int i=0;i<5;i++) {
System.out.println("Thread :" + name + " #" +i);
Thread.sleep(5);
catch (Exception e) {
e.printStackTrace();
class threadRunnableTest {
public static void main (String args[]) {
Runnable runnable=new NewThread("BaSkAr");
Thread thread = new Thread(runnable);
try{
System.out.println("First Thread is starting !!!");
thread.start();
Thread.sleep(2000);
System.out.println("First Thread it to be stopped!!");
thread.stop();
System.out.println("Second Thread is starting !!!");
thread.start();
Thread.sleep(2000);
System.out.println("Second Thread it to be stopped!!");
thread.stop();
catch (Exception e) {
e.printStackTrace();
It's usually helpful to check the documentation:
[http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#start()|http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#start()]
start
public void start()Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).
It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.
So, make a new java.lang.Thread

Similar Messages

  • How to run the program for specified time

    Dear Friends,
    I have a small problem, I want to run my labview program for specified amount of time, Say for example it might be 1 hour or 5 hours or 10 minutes or even milliseconds(The time will be specified by the user).
    How to write programs for this
    And I want to get the system time in an instance, how it can be achieved,
    Could you please help me?
    Regards,
    Rathan

    Hi,
    Herewith my screenshot attached. There are thre inputs thres, tempX, xValue, it is in side the while loop.'xValue' will be acquired every iteration, It will be saved through shift register and acquired to 'tempX' for the next iteration, 'thres' is a constant value. I'm doing some logic, and calculating the dvalue and convert it to a string and concatenate it with end of line character, then after writing it into a file.
    In the logic, inside of the functional logic  I'm assigning some values dValue, if the logic is true or else dvalue will be 0
    What I require is I don't want to write the dValue in to a file, if it is equal to zero. Could you please help me, how to tackle this problem?
    Thanks.
    Regards,
    Rathan   
    Attachments:
    writing except 0.GIF ‏9 KB

  • HT1420 how to deauthorize all computers for second time in one year?

    hi there....
    first sorry for my english.
    i have allready deauthorize 5 computers one time and after authorize again 5 computers , i wan to do the same think but i cant before 1 year .
    now i cant connect my iphone to i tunes.
    what can i do for this problem?
    thanks for your help.
    p.s.
    i have allredy search for solution on itunes support page and i didnt find anything.

    You can't. You can click the Support link under Quick Links and email for assistance.

  • Running a thread for a specified time

    my main program has 10 threads. i want to run each thread for 30 secs . but if one thread is on progress it may be allowed some time to complete its task otherwise evrbody should return after 30 secs.how can i do it ?
    thankx

    code is hanging...
    also how do i do >>if one thread is on progress it may be allowed some time to complete its task otherwise evrbody should return after 30 secs
    class Shared
    boolean stop=false;
    // do nothing but helps only for synchronisation
    class ThreadProducer1 extends Thread
    {    Shared obj;
         public void run()
         {   long endTime = System.currentTimeMillis() + 30 * 1000;
             long currentTime;
              for (int k=0;k<1000;k++)
              {System.out.println("thread1");     // doing its work
             currentTime=System.currentTimeMillis();
              if (currentTime>endTime) break;
    class ThreadProducer2 extends Thread
    {   Shared obj;
         public void run()
         {   long endTime = System.currentTimeMillis() + 30 * 1000;
             long currentTime;
              for (int k=0;k<1000;k++){
              System.out.println("thread2");     // doing its work
              currentTime=System.currentTimeMillis();
              if (currentTime>endTime) break;}     // doing its work
    class ThreadProducer3 extends Thread
    {   Shared obj;
         public void run()
         {   long endTime = System.currentTimeMillis() + 30 * 1000;
             long currentTime;
              for (int k=0;k<1000;k++)
              System.out.println("thread 3");     // doing its work
              currentTime=System.currentTimeMillis();
              if (currentTime>endTime) break;
              }     // doing its work
    class Test
    public static void main(String argv[])
        try{
         ThreadProducer1 t1 = new ThreadProducer1();
         ThreadProducer2 t2 = new ThreadProducer2();
         ThreadProducer3 t3 = new ThreadProducer3();
         t1.start();
        t2.start();
         t3.start();
        Thread.sleep(30000); // main thread wakes up after 30 secs.
         }catch (InterruptedException ex)
             System.out.println("exception");

  • How can we process the CRM Order again for second time in debugging mode

    Hi,
    Can anybody please tell me how can we process the CRM ORDER for second time.  that I want to process in debugging mode.
    Thanks,
    bsv

    Hi bsv,
    Are you trying to reprocess a BDOC for debugging purpose?
    If the BDOC is not with a final status, you will be able to reprocess it using the reprocess button in the smw01 search result list.
    And you may put /h on the popup when you click on the 'reprocess' button.
    If it is allowed to make some changes in the CRM ORDER for testin purpose, it would be easier to perform debugging.
    A more 'careless' way is to deactivate the outbound or inbound queue in transaction smqs or smqr, then in smq1 or smq2 to locate the interested queue, and click on button 'debug LUW'.
    Hongyan

  • The FM "RV_PRICE_PRINT_HEAD" is not runnging for second time...

    Hi All
    The FM "RV_PRICE_PRINT_HEAD" is not runnging for second time, first time it works fine and second time it is giving the null values. Will you please solve this problem (is there any flag to recall the function ex: run the FM press f8 and come back f3 and press again f8 - first time it is showing the data & at second time f8 it is not showing any data ).
    Feilds filled in head_i structure are:
    VBTYP,
    KALSM,
    KNUMV,
    WAERK,
    KAPPL.
    Thanks,
    Ravi
    Message was edited by:
            Ravi Kumar
    Message was edited by:
            Ravi Kumar

    Hi,
    before <b>every</b> call of RV_PRICE_PRINT_HEAD or RV_PRICE_PRINT_ITEM you should call RV_PRICE_PRINT_REFRESH once - you have to pass a dummy parameter.
    No idea why this is so but SAP does it the same way
    Regards,
    Clemens

  • Script runs not corrextly for first time

    Hello,
    i have kind a strange problem.
    Always wenn i run my script first time (after opening Diadem), it works not corretly. Specificly creating a report goes wrong.
    When i start the script for second time (and each additional time) everything works fine and correctly?!
    For understand:
    - I do some (mathemtical) analyse  - always works correctly
    - Load/Append prepared ReportLayout, add curves, create text objects - doesn't work for the first time, then it alwas works correctly
      The mistake is, that all curves (that should be in several appended layouts and text objects) are added in the first loaded report sheet (though the reportsheets were appended)
    As i said, when i start the script second time (and each additional time) everything works fine as it should?!
    Thanks
    Solved!
    Go to Solution.

    Hello,
    yes i tryed with debugger step by step. No errors. Ironically with debugger step by step everything works fine (even for he first time)
    It looks like, when i run the script for the first time, the appended report sheets are not active, because all curves are added in the first report sheet.
    But why works it wrong only for the first time and then everything works fine?
    Thanks

  • In oneasset class i have created 2 assets by using of aso1 after that i acquired one asset for that i run the depreciation for first 5 periods, it has been showing depreciation for those period but if i am trying to run the depreciation for second asset i

    in on asset class i have created 2 assets by using of aso1 after that i acquired one asset for that i run the depreciation for first 5 periods, it has been showing depreciation for those period but if i am trying to run the depreciation for second asset it is not showing first 5 periods why it is not showing? Is there any reason?

    Hi
    Repeat run you can do only for the last depreciation period. For the asset which you are tryin to post depreciation from July to Jan, please check the asset value date which you have given while posting the transactions or in the asset master.
    If the asset value date is in July, then deprecaition from July - Jan will get posted in the current month depreciation in total. You will not be able to post depreciation individually month wise using AFAB.
    REgards
    Malathi

  • How to get wage type for every time record

    Hi Pros,
          I am using DS 0CA_TS_IS_1, it includes report time type (0REPTT), but not have wage type. in CATSDB, I fied fields for attendance/absence type and wage type. but not every time record has wage type. can you please tell me how to get wage type for every time record? what is relation between reporting time type, attendance/absence type and wage typs?

    Hello,
    Can you talk to your HR/T&E functional consultant if they populate these values in CATSDB table using standard way or if there are custom fields that are in CATSDB OR any other table which can be used to meed the requirements
    Thanks
    Abhishek Shanbhigue

  • How To run Currency translation for Consolidation Application in BPC NW

    In "How To do Currency Translation for Financial Application in BPC 7 NW", the author mention that there is another "How To run Currency translation for Consolidation Application in BPC NW", anybody know where to get it?

    Hi...
    Check if the below links are useful to you.....
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/6052a57b-8c64-2c10-b3a5-b0378ff21243&overridelayout=true
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c0ea1fd8-d6d3-2a10-c1ab-e8164dd98316
    You can find all How-to docs in the below link
    http://wiki.sdn.sap.com/wiki/display/BPX/EnterprisePerformanceManagement%28EPM%29How-to+Guides

  • How to run Crypto Tools for SSO Enabling

    Hi Friends,
    How to run Crypto tools for SSO enabling. If any body knows please help me...
    Thanks

    Hi ;
    what is the script for windows Environment...

  • How to run wfstatus.sql  for i-Expenses

    how to run wfstatus.sql for i-Expenses in 11i EBS.

    Pl see MOS Doc 295078.1 (Maintenance Pack, Patchset, and Rollup Patch Level for Internet Expenses 11i)
    HTH
    Srini

  • Error -1073807346 will get away when i run VI for second time

    This is the weird thing
    i open the vi for the first time and run it and it will put out the error :
    Error -1073807346 occurred at VISA Open in Prompt for com port.vi
    Possible reason(s):
    VISA:  (Hex 0xBFFF000E) The given session or object reference is invalid.
    i run the vi for the second time and the error goes away.. and everything works...
    i dont know whats wrong, have you had this problem also?
    Attachments:
    serial.png ‏31 KB
    serial.png ‏31 KB

    You know that almost threw me untill I re-read the vi name!
    Dude, that's not how you write a "Prompt User" routine!  What is happening is that you read the VISA In Terminal run that value through the for loop (At warp speed burning a cpu core) while the user fiddles with the VISA in terminal.  BUT, nothing changes the value on the wire!  so you pass the "Old" value to the VISA Open.
    I've been meaning to add Prompt(VISA).vi to my reuse for a while anyhow.  Thanks for the excuse.
    Jeff

  • How to run a VI for very short time, e.g. 100ms?

    Hi,
    I need to run a VI for very short amounts of time, say 100ms, 200ms, 500ms or 1s. I want to get this time from the user, maybe as a control variable. How may I do this? I tried using the "elapsed time" function but seems like it was not meant for such small time periods. Any ideas?
    Thanks
    Kaiser 

    What are you trying to do in the "short time"? When you say "run a VI" do you mean "start, run and stop running", or do you mean for the vi to do something for the specified time, i.e. flash a front panel LED for a precise period after the operator clicks a button? In the later case 100mS is actually fairly long, and can be accomplished with various timing functions, with varying degrees of accuracy. The most accurate, in a Windows environment, would probably be the timed loop. If you need really accurate, particularly if you are interfacing with hardware (a pushbutton, an actual lamp, etc.) a real-time system would be the best bet.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • Cannot run a jsp a second time in WebLogic Portal 10.3

    I have an index.jsp that has bunch of links that build pdfs.
    here's the code from the jsp that builds the links
    <netui:anchor action="openDocumentForView" target="new">view
         <netui:parameter value="${container.index}" name="id"/>
    <netui:parameter value="${container.item.documentType}" name="type"/>
    <netui:parameter value="${container.item.imageToken}" name="imageToken"/>
    <netui:parameter value="${container.item.tokenId}" name="
    </netui:anchor>
    the idea is that it opens a new window and streams a pdf.
    The action in the jpf does the forward like this
         URI uri = new URI("showImage.jsp");
         System.out.println("uri = " + uri.toString());
         return new Forward(uri, true);
    the showImage.jsp looks like this:
    <%@ page import="java.io.*, java.util.*"%>
    <%
    System.out.println("showImage.jsp ran....");
    response.setContentType("application/pdf");
    byte[] pdf = (byte[]) request.getSession(false).getAttribute("imageObject");
    request.getSession(false).removeAttribute("imageObject");
    response.getOutputStream().write(pdf);
    response.getOutputStream().flush();
    response.getOutputStream().close();
    %>
    What happens is:
    I click on one link
    the new window opens
    in the controller the pdf is built & put in the session
    in the new window, showImage.jsp is loaded and the pdf is displayed.
    Then I close the showImage.jsp window, in the first window I click another link
    in the controller the new pdf is built & put in the session
    in the new window the previous pdf is sent to the user.
    the jsp doesn't run a second time ( there's a print statement that never runs, so I know the jsp never runs, and a few other tests).
    It's not cached in the browser, I've used response.setHeader to prevent other caching.
    so I'm stumped.
    Does anyone know how to get this jsp to run everytime it's called?
    Thanks
    John
    Edited by: user11142479 on Mar 9, 2011 12:51 PM

    I don't recall the product shipping a facet called Mobility Framework. This might have come from another product called WebLogic Mobility Server. I do not believe that this product exists anymore since the Oracle purchase of BEA. This product came from a partner called MobileAware and I think you can still purchase it from them if you require it.
    However, you might want to read about the native capabilities in WLP for handling multiple devices. Read:
    http://download.oracle.com/docs/cd/E13155_01/wlp/docs103/portals/multichannel.html to see if this is sufficient for your requirements.
    Brad

Maybe you are looking for

  • Table VBKD

    In table VBKD you have a POSNR 000000 for header data and then POSNR e.g. 000001 for item 1 on the sales order. According to me a POSNR not equal to 000000 will only be created when you have different purchase order data per item. When does the syste

  • BADI or User-Exit for Adding New Input Field in 0VTC

    Hi Experts, Has any of you worked on enhancing transaction 0VTC (Define Routes and Stages)? I have a requirement right now to add two new input fields in New Transport Routes screen. Could anyone provide a BADI or customer exit that I could use to mo

  • Oracle OS User on Unix

    Hi all. I am running Oracle 9i on Solaris 9. I can get the OS User by executing the following select: select sys_context('userenv','os_user') from dual; My question is, how does Oracle pick up this OS User? Is there a way to spoof the user? Thanks in

  • Bex Formula for calcualting Value from Quantity & Price

    Hello, In my query I need to calculate the value by multiplying Quantity available in my cube and net price in my material master attribute. How can I do this? I tried creating a formula variable for net price and multipied it with Qty but it still s

  • Logging Client-IP on IWC behind a reverse proxy

    I've a Convergence 2 configuration where IWC is contacted through a reverse proxy. The reverse proxy sets Client-IP header. I'ld like to log that Client-IP information in IWC log. Is this possible? Regards.