How to start, stop and restart task

Hello Everyone,
Need advice on what is the correct way to start, stop and restart a Java task?
I have tried with Executors.newCachedThreadPool() or fixedThreadPool() however I was only able to submit the task once. My program crashed when i tried to resubmit the task again after a shutdownnow command()

Tasks are designed to be run once. If you want restart functionality, use a service:
http://docs.oracle.com/javafx/2/api/javafx/concurrent/Service.html
The sample service I posted in the following thread demonstrates how to do this:
Multithreading
Use of Executors is not necessary as a Service encapsulates the execution thread management (though you can set your own executor on the service if you really needed it). All you need to do is make use of the service start, cancel, restart and reset methods as required. If you do use the cancel method, then you need to make sure that your service is properly interrupt aware for the cancel to function as you expect.

Similar Messages

  • Start, stop and restart while loops

    Hi, my qustion is i have 2 example a and example b. Example b lets u start counting up in seconds when u want to. as long as the toggle switchs are in correct position. it also lets u start, stop and restart if need be. i want to be able to that with example a, but for some reason the while loop always sets of running independent of what position the the toggle switch. Any help greatly appreciated.
    Thanks Stuart
    Attachments:
    examplealib.llb ‏202 KB
    exampleb.vi ‏25 KB

    An example as the attachment.
    Attachments:
    switch.vi ‏23 KB

  • Shell script to start, stop and restart a JAR

    Hi everyone,
    Does anyone have idea to write a shell script to start, stop and restart a JAR under linux? it can indicate a method or parameter? Thanks!
    this JAR inculdes a class with main method like this:
    public class Client(){
      public Client(String name){
      public void stopClient(){
      public static void main(String[] args){
         new Client("/tmp/text.log");
    }

    Does anyone have idea to write a shell script to
    start, stop and restart a JAR under linux? That part isn't really clear.
    Start would be java -jar myjar.jar.
    Stop could either be kill, which kills the whole process; kill -TSTP, which suspends the process, or some application-specific communication such as sending something over a port; or putting something into a file or something.
    Restart could just be the same as start (if stop is just kill); kill -CONT, if stop was kill -TSTP; or some other app-specific communication.

  • Shell script to start, stop and restart a JAR under linux

    Hi everyone,
    Does anyone have idea to write a shell script to start, stop and restart a JAR under linux? it can also indicate a method or parameter? Thanks!
    this JAR inculdes a class with main method like this:
    public class Client(){
    public Client(String name){
    public void stopClient(){
    public static void main(String[] args){
    new Client("/tmp/text.log");
    }

    Does anyone have idea to write a shell script to
    start, stop and restart a JAR under linux? That part isn't really clear.
    Start would be java -jar myjar.jar.
    Stop could either be kill, which kills the whole process; kill -TSTP, which suspends the process, or some application-specific communication such as sending something over a port; or putting something into a file or something.
    Restart could just be the same as start (if stop is just kill); kill -CONT, if stop was kill -TSTP; or some other app-specific communication.

  • How do I start, stop and restart a sequence with a periodic input?

    Hi,
    I have written some code that will monitor my com port (rs-232) continuously for an ASCII character (in this case a 'P'). When the P is received, I want a sequence structure to start working. The P will only appear once for a short while, but the sequence should carry on running until it finishes all the frames. On the next time a P appears on my monitor, I want to either stop the sequence structure regardless of which frame its in and restart the sequence from the beginning again or to run the sequence from the start again if it has already completed all the frames.
    What sort of structure do I need to do this, are there any examples?
    James

    James,
    Indiana is correct, my take on this is similiar.
    If you have a 3 element sequence structure for example which runs if 'P' is returned from your COMs thread, you will need to query a variable in each element of the sequence in order to suspend execution of the next/remaining elements in the sequence if this event occurs. You can do this by reading the variable that your COMs thread sets using a case structure in each element of your sequence. In order to re-run your sequence if 'P' is returned during the execution you can simply set the suspend variable and ensure the code is in a while loop to recall the code.
    See the attached example code/screen shot:
    This is however not an elegant solution and the best way would probably be using the events structure and a user event to queue the P events. This is available in 6.1 but I believe its the professional package. See also my implementation using this method, again attached below:
    Hope this helps,
    Kind Regards
    Steven Bird
    Applications Engineer
    National Instruments
    Attachments:
    Example.JPG ‏194 KB

  • How can I stop and restart a .vi with a single front panel button?

    Hey guys, a newbie here.
    I have a .vi with a stacked sequence. The first few frames are hardware initialization and settings (LIN master node) and the data the hardware should transmit (frame response table). In the next frame there's a loop in which the hardware sends and recieves data (LIN monitor). If I want to change the initialization, settings or data values, I have to stop the .vi and restart it. I was wondering if there is a simple way of doing this with a single click (a button on the front panel).
    An alternative would be to put another loop outiside the whole stacked sequence and then run it a single time with a push of a button (the inner loop should let the outer one restart), is that possible?
    I hope I made any sense. Thanks for any suggestions.
    Tomaz
    Solved!
    Go to Solution.

    Ideally, redoing the code with a state machine would be the best way to go, if only so that you can add this powerful tool to your toolbox. That being said, wrapping your existing code in a while loop, with its own stop button to stop the program, will work if executing the entire sequence is ok. Where you might run into problems with this is if there is a step in the sequence that shouldn't be executed again, then it would require wrapping that sequence frame's code in a case statement that executes only the first time through. If you have the time, learning how to use a state machine would be a real benefit, really taking your LabVIEW knowledge to the next step, if you pardon the pun.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • TS4036 How do I stop and restart a backup from iCloud on an iphone

    Trying to reload the back up from iCloud and it still at 5.3 of th 5.5gb back up since 8/27

    Here I'll show you a method using computer iTunes to create ring and text tones:
    1. Select a title (.mp3 or .m4a) in your iTunes Library
    2. Do File > Get Info on selected title (Windows do Edit > Get Info)
    3. In the dialog choose Options tab
    4. Set Start Time and End Time (no more than 35 secs otherwise won't work, and text tone around 25 secs)
    5. Close dialog.
    6. Now control click the title (right click) and choose Create AAC Version
    Note: If you don't have Create AAC version, switch in menu File > Preferences...(Windows do Edit > Preferences...) > General > Import Settings... > Import Using: AAC Encoder.
    7. When it is done, drag the newly create title to the desktop.
    8. Delete the newly create title in iTunes. <-- This step is important
    9. Rename the title on your desktop from ringtone.m4a to ringtone.m4r
    10. Drag and drop it into iTunes
    Now you have a ringtone.
    Make sure it is selected in iTunes for syncing with your new iPhone.

  • How can I stop and restart the ApplePhotoStreams.Exe process on my Windows 7 computer?

    I sometimes notice my CPU utilization skyrockets and my computer fan switches to high. This happens sporadically. The process causing this is ApplePhotoStreams.Exe. It appears the process goes into some infinite loop trying to update or sync pictures. Applications on my PC slow down and the fan stays on high (which is really loud) until I cancel the ApplePhotoStreams.exe process. I can easily cancel the process using Task Manager, but then any photos I take with my iPhone do not replicate over onto my PC unless I reboot my computer.
    I'm not sure if anyone can easily tell me why ApplePhotoStreams.exe is doing this in the first place, but I would more like to know how to restart the ApplePhotoStreams.exe process after I cancel it without having to reboot my PC.

    you can download a new installer and serial number from Adobe at Adobe - CS2 Downloads

  • Shell script for start stop and restart standard

    Hi,
    I'd like to know if there's a standard template for shellscript for a kind of stop|start|restart execution of a server or stub.
    If you have any link or some info that explain how to do that nicely it would be nice!
    Thank you

    There's plenty of live examples in /etc/rc.d

  • How to start, stop or restart a J2EE Web application in NetWeaver

    Whicht tool for that task?
    Where to find it?
    I need something like the tomcat manager

    Hi Ludger,
    I think you can use jcmon for that,
    read,
    http://help.sap.com/saphelp_nw04s/helpdata/en/d3/4d074147c1f06fe10000000a1550b0/frameset.htm
    Edited: Actually it doesnt frestart web application but is another way to restart processes in the J2EE engine
    regards
    Juan
    Please reward with points if helpful

  • How do I stop and start a Swing Timer?

    I have created a Swing timer;
            new Timer(250, Task).start();but can't figure out how to use the .stop() and .restart() methods?
    How do I code this?
    TIA

    I found the answer;
      SimKitsControlTimer = new Timer(250, SimKitsControlTask);
      SimKitsControlTimer.start();Not as prevously written.
    I was trying to create an object with the .start() method at the end of the line. Doh!

  • How to Stop and restart the midtier?

    Hello All,
    I have installed Oracle AS (Infraturcture & middle tier , BI & Forms) on same Linux box.i.e: Oracle As 10.1.2.0.2 (Rel 2, x86 for Linux), SLES 9
    Here is my question:
    How to Stop and restart the midtier?
    Regards,
    DN

    biforms.sh
    export ORACLE_HOME=/opt/oracle/biforms
    export OH=$ORACLE_HOME
    export PATH=$OH/bin:$OH/opmn/bin:/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/java/bin
    export ORACLE_SID=ORCL
    export LD_LIBRARY_PATH=$OH/lib:/usr/openwin/lib:/usr/dt/lib:/usr/lib:/tools/lib
    infra.sh
    export ORACLE_HOME=/opt/oracle/infra  <-- or correct one!
    export OH=$ORACLE_HOME
    export PATH=$OH/bin:$OH/opmn/bin:/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/java/bin
    export ORACLE_SID=ORCL
    export LD_LIBRARY_PATH=$OH/lib:/usr/openwin/lib:/usr/dt/lib:/usr/lib:/tools/libAs you see, only the first row differs from these two scrips. Because I'm lazy, I usualy set export OH. Under certain circumstances you might want to add DISPLAY to biforms.sh. Set it to localhost:0 or whatever is correct.
    Martin

  • How to Stop and restart the OC4J_BI_FORMS?

    I have Oracle AS 10.1.2.0.2 (Rel 2) installed. (Infratsructure & BI & Forms) on same computer.
    my question is :
    How to Stop and restart the OC4J_BI_FORMS?
    Regards,
    DN

    Just as any other OC4J:
    opmnctl stopproc -process-type=OC4J_BI_FORMS
    opmnctl startproc -process-type=OC4J_BI_FORMS
    or
    opmnctl restartproc -process-type=OC4J_BI_FORMS
    cu
    Andreas

  • How to start/stop Event Mgr. and RFID information server?

    I take over our form RFID admin (who quit) position.
    I cannot find any document which tells me How to start/stop Event Mgr. and RFID information server.
    Even the "Sun Java System RFID Software 3.0 Administration Guide" does not have this piece of info.
    Would you please help? Points guaranteed. Thanks!

    Ashley you are still not clear to me.
    Please mention what applications are these??
    Is it SAP Event Manager??
    What is the RFID Information server??
    Is it SAP based, or some other vendor??
    How is the integration done?
    Thanks

  • After updating 10.9.2 update the computer stops and restarts abruptly and systematically whenever it is in standby.  Please how to fix this ?

    Hello,
    I'm french, sorry my bad english. Please Help me !
    After updating 10.9.2 update the computer stops and restarts abruptly and systematically whenever it is in standby (sleeping).
    This message apeaars : “Your computer restarted because of a problem”
    Please how to fix this ?
    I tried an SMC reset PRAM and reset, but not result !
    I have not installed new software or plugin. Only updated OS X 10.9.2.
    With 10.9.1 or earlier I never had a problem !
    Thank you for your help
    Francisco to Paris

    Hello FM-Paris,
    Thank you for the details of the issue you are experiencing with your Mac mini.  I would be concerned too if my Mac mini was restarting unexpectedly.  I recommend following the steps in the section titled "Troubleshooting a recurring kernel panic" in the article below to help isolate and troubleshoot this issue:
    OS X: When your computer spontaneously restarts or displays "Your computer restarted because of a problem."
    http://support.apple.com/kb/TS4636
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

Maybe you are looking for

  • 2 Apple TV on one Itunes account?

    Can I have 2 Apple TVs stream for ONE iTunes account? One is 2nd and one is 3rd Gen... and they are Wfi off the same ID/acct Do i need any special configuration in ApTV?

  • DVD drive does not recognise CD/DVD

    Ok. SO recently my G42-230US notebook computer just does not play CD/DVDs. The drive opens, the green light appears on the side but when I go to my computer, my DVD/CR ROM drive does not appear. Can I get some help with this problem?

  • How to make mutiple shortcut keys in one text entry box

    I'm trying to make F8 and Enter work in one text entry box and only one because I need to make the scoring work the way I want it to. I have made both F8 and Enter work, however they are both in seperate text entry boxes when I want both to work in t

  • Can't able to speak in normal mode. Able to talk only in speaker mode

    Dear Team, I bought the Z10 yesterday, When I make a call, the opponent persons can't hear when I talk in normal mode. They can able to hear me only when I put the call in speaker mode. Please do the needful

  • Software Update periodically stops downloading

    This is the closest category I could find to post this in, so I apologize if it's in the wrong one. Here is my problem: I am running Software Update, and everything is working fine, expect the download will from time to time (sometimes quite frequent