How to implement a forever running program?

i made a program that does some file i/o in an infinite loop (while(!stop)). if all work is one it waits until "jnotify" notifies that a new folder was created and it starts working again. this program has a jmx interface to start and stop this loop. all functionality is done only the main() is missing now.
how to implement a forever running main, only waiting for (user)-methods called to execute them - just like any gui-application? i guess in a swing-app there is no while(!closed)-loop? (in meantime i noticed - such loops consum 100% cpu ;-)). So is there a best practice or a "pattern" for such common apps?
thx in advance

817113 wrote:
in my case the "inner-jnotify-file-io"-thread it self is stoppable (while(!stop) listen for jnotify events). but if this thread is stopped the hosting main-method must keep runnning - waiting until someone calls start() via jmx or shutdown(). Strictly speaking the main methods only task is to host the jmx interface (, the logger..) and to run until someone calls shutdown (like a swing gui that waits until someone closes the window).
How to implement such behavior? Do i need another thread within main, waiting for such an event and message it to the hosting main method? Main already runs in its own thread, if your "inner-jnotify-file-io"-thread has to be able to be stopped (instead of just paused), then you need another thread that stays alive.
You could make the main thread wait() on something that gets notified() when close is called.
(i could hardly believ that there is no "pattern" or example fo a main()-method/app that is running until someone calls a "close"-methode)No, you're just not understanding the big picture here. It's quite easy to make an app like that. And you've been given ways and information on how to do it.

Similar Messages

  • How to start a long running program at system start and stop at login and restart at logoff

    I am trying to mine some crypto currency with my computer. My computer is usually in logged off state, so I want to mine automatically when system is in this state.
    Untill now I have done this:
    At system start, I have scheduled a task to start the mining software
    at login I have scheduled another task to kill the mining process
    Here comes the question: I need to restart the mining process as soon as the user logs off.
    But I couldnt figure out how to schedule a task at logoff, so I decided to use Group Policy Ediotr's Logoff scripts. But the problem is, I can't seem to log off at all, because system seems to be waiting for the "script" to finish, and since it is
    a mining process, it doesn't finish, and the user is never logged off!
    How do I configure windows to resume mining after the logoff?

    Hi!
    I haven't been working much with mining, but you are thinking correctly with using the logon/logoff-scripts.
    The problem is that the process for mining requires a user to be logged on, it runs i user-context.
    So if you in some way can start the process to run in system context, you are good to go. (The mining process) But if this is possible at all I do not know, I think the miners are dependent on a user being logged on.
    Best regards
    Andreas Molin
    Andreas Molin | Site: www.guidestomicrosoft.com | Twitter: andreas_molin

  • How to clear running programs

    How do I clear the running programs on my iPad 2?   I fingured out how to bring them up - pushing the button 2x.  I figured out how to check them - hold button down.  but How do I clear them?

    Shut down an app...
    - From any Home Screen, double tap the home button to bring up the Recents List
    - Tap and hold any icon until they wiggle
    - Press the red to delete the offending app from this list.
    - Press the home button twice when done.
    - Restart the app
    Note that the vast majority of apps cannot and do not run in the background.  For more info on Multitasking...
    http://support.apple.com/kb/ht4211
    http://whenwillapple.com/blog/2010/04/19/iphone-os-4-multitasking-explained-agai n/
    http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html
    http://speirs.org/blog/2012/1/2/misconceptions-about-ios-multitasking.html

  • How to implement a print screen through a java program rather than a keyboa

    help needed urgently to make a college project.
    have to capture whatsoever is on the client screen
    and sent it to to a server program where it will be made visible on a frame or panel.
    this is to be done without the client ever knowing it.
    so needed to implement a printscreen command using java code and put it in a program(also how to make
    the .class file containing this code run in the background all the time since the client comp starts till it is shut down without the client ever knowing it)
    e mail: [email protected]

    <pre>
    hartmut
    i need help.
    i've recently started using the web to learn more about java.your reply was very discouraging.
    the proff. just wants a decent project.
    but i want to make this project to improve my java networking skills.
    if you can help , please tell me how to implement a printscreen through a java program rather than a keyboard.
    I'll be very grateful to you if you can help me in this regard, but please dont send a dissapointing response like the previous one.
    mail: [email protected]
    </pre>

  • I am having a problem w/ my itunes working correctly due to accidentally running Itunes through my troubleshooting, running programs made for previous versions of windows!! How do I turn it off?!??

    I am having a problem w/ my Itunes working correctly, after accidentally running Itunes through my  troubleshooter  to, Run Programs Made For PreviousVersions of Windows. It keeps popping up that the Compatibility  Version is on, to make sure it's off before opening my Itunes Account. I've looked everywhere, Please, Please, How Do I Make This Right??!??

    It sounds like either your hard drive or the SATA cable that connects it to the motherboard are failing. This could be heat related in your case, which is why you see it after it runs awhile. You can take it to the Genius Bar for a free evaluation. If you decide to test it yourself, I usually suggest moving the hard drive to an external enclosure. If it works there for awhile, the cable is probably the issue.
    http://www.amazon.com/Sabrent-2-5-Inch-Aluminum-Enclosure-EC-TB4P/dp/B005EIGUD4/ ref=sr_1_3?ie=UTF8&qid=1397647657&sr=8-3&keywords=2.5+enclosure
    http://www.ifixit.com/Device/MacBook_Pro_13%22_Unibody_Mid_2009

  • I've downloaded CS6 Master Collection but only see The Photoshop icon.  I can't seem to find the other programs, except on "uninstall programs" How do I open and run the others?

    I've downloaded CS6 Master Collection but only see The Photoshop icon.  I can't seem to find the other programs, except on "uninstall programs" How do I open and run the others?

    How about you give us some real information.
    Did you install the software? What operating system?

  • How to get main class name in running program?

    How can I get classname, which main method is executed? Of course in running program?
    Please help,
    Chris

    Something like (not tested this)StackTraceElement[] foo = new Throwable().getStackTrace();
    String whichClass = foo[foo.length-1].getClassName();

  • How can I install and run a Windows program on my MacBook Pro/?

    How can I install and run a Windows program on my MacBook Pro?

    You have several options.
    1, Use a Virtual Machine like Vmware, Parallels etc... to Create a Virtual Windows Installation and Run your program in there.  A Virtual MAchine will runn in a Window on your Desktop and share your Mac's resources RAM HD space processor. Your MAc desktop will still be available while you run Windows install.
    http://www.parallels.com/
    2. Install Windows on a partition using Bootcamp. It will run a full installation of Windows you can boot into, and run your programs.  The Mac desktop will not available until your reboot the computer and start in OSx instead of Windows.
    https://www.apple.com/support/bootcamp/
    3. Use Wine /  Winebottler to run the Application without the need for a complete Windows installation.
    http://winebottler.kronenberg.org/

  • How can I get a display of all running programs in lion like I used to get when I did a 4 finger swipe in snow leopard?

    how can I get a display of all running programs in lion like I used to get when I did a 4 finger swipe in snow leopard?
    I liked to turn off running programs without a window that I was no longer using
    thanks.
    Best I can do now is to open the "force quit" window and click on programs I want to stop and then send each one a "command-Q" and then repeat as necessary
    Jeff

    Command + Tab is what you are after i think

  • Ios 7.0.2 issue: how to stop running programs

    I am a new iPhone5 user and just installed ios 7.0.2 (maybe I should not have but I did). Now I don't know how to stop running programs. Previously
    I double-clicked the Home button, then saw the icons that represented running programs, then could lightly touch one of them which led to all of them
    showing a X for a potential delete. That does not work now so how do I do it?

    Double click the home button and then swipe up on the app screenshots.

  • Please do the following: -Close any running programs -Empty your temporary folder -Check your internet connection (Internet-based Setups) Then try to run setup again. Error code -6003. How do I empty temporary folder?. Thanks. Allan

    I am having a problem installing Nikon Codec, software to view photos and get this error error message: Setup has experienced an error. Please do the following: -Close any running programs -Empty your temporary folder -Check your internet connection (Internet-based Setups) Then try to run setup again. Error code -6003. How do I empty temporary folder?. Thanks. Allan

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    * Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    * Tools > Options > Privacy > Cookies: "Show Cookies"
    *http://support.mozilla.com/kb/Deleting+cookies
    *http://support.mozilla.com/kb/How+to+clear+the+cache

  • HT201365 How do I stop the running of programs in the background?  The old way of doing it doesn't work now.

    How do I stop the running of programs in the background?  The old way of doing it doesn't work now.

    How to Close Apps
    Double Tap the Home Button... Then swipe the App (not the icon) Upwards... Tap the Home Button when finished.
    From Here  >  http://support.apple.com/kb/HT4211

  • I keep getting "an error occurred when installing, please run program again" for OS X mountain lion, how can i fix the problem?

    i keep getting "an error occurred when installing, please run program again" for OS X mountain lion, how can i fix the problem?

    The Reset feature adds a folder on your desktop named Old Firefox Data. I recommend hanging onto that for a few weeks in case you discover something essential that the Reset feature left behind.
    This article has a list of what is migrated and what is not during a Reset, in case you're curious: [[Reset Firefox – easily fix most problems]].

  • How to implement erase function of paint program?

    Hello all:
    there are many demo programs on the website that indicates how to implement
    a simple draw line java program.
    However, i didn't find available source to learn how to implement the erase function,
    so that we can erase part of line or all lines.
    Some programs present the methods to do undo operations, however none of them
    related directly to how to implement erase function.
    thank you for comments
    -Daniel

    Hello all:
    there are many demo programs on the website that
    indicates how to implement
    a simple draw line java program.
    However, i didn't find available source to learn how
    to implement the erase function,
    so that we can erase part of line or all lines.
    Some programs present the methods to do undo
    operations, however none of them
    related directly to how to implement erase function.
    thank you for comments
    -DanielThere are a few ways depending on the app requirement or design.
    The simplest one is to draw with the background color, typically white.

  • How to implement email facility in PL/SQL programs.

    Is there any Oracle package which supports email facility?
    I have some dbms automatic jobs fires every half hour, in case there is any failure in the process I would like to send an email to user or the person who is running the job.
    Can some body tell me how to implement it in PL/SQL?????????????

    You might find this article useful..
    visit..
    http://www.oracle.com/oramag/code/tips2000/090400.html

Maybe you are looking for

  • Design canvas editor not working

    I think I may have started the program before the auto-updater finished it's work. After closing it up and restarting it I was no longer able to see the design canvas editor for any of my projects. Thinking I may have screwed something up I re-instal

  • The thumbnail images have disappeared from one of my sequences

    I have 3 sequences open in the timeline and the thumbnail images have disappeared from the clips in one of them. It's very frustrating to work without them, how do I get them back?

  • Mac mail will not add new accounts

    Hi, Recently I added two new email accounts to my mac Mail Then the account started acting weird a few days ago-not letting me email myself (to a gmail account), refusing to put the email in the address field. Thats the email associated with my compu

  • Sync fail - files accessed via app always older versions

    Hi, I have a 2TB My Cloud device and various Android devices running the My Cloud App. I have the app set to auto-sync every 120mins however when accessed via the app my files are always older versions, often by a couple of months. The time stamp sug

  • Open up any folder and the icons move around randomly

    every time i open any folder all the icons move around for a phew seconds then when i try to click what i want it moves around again... now this is massively annoying as i always seem to go into the wrong folder then have the same thing when i go int