Should i let Main() exit while worker threads are still running?

what is the Java Best Programming Practices for the issue of having the
public static void main(String[] args) { ... }exit before the worker Threads that is starts exit?
letting main() exit first, or making it wait, has no practical difference.
yet, when others look at my code, what should it look like?
should i thread.join() on all worker threads, before main() exits?
imo: it appears to be bad style to let the main() exit while my session with the jvm is, essentially, still running.
yet, it is extra code that is not necessary.

Strike that. Reverse it.
i.e.
>
1) Have main join the threads, and comment that you're doing so simply to preserve the notion of main as the umbrella for the program.
2) Make the threads daemons, and comment at the end of main that the daemon threads, and hence the program, may still run after main has completed.
>
should instead say:
1) Make the threads daemons, and have main join the threads, and comment that you're doing so simply to preserve the notion of main as the umbrella for the program.
2) Make the threads non-daemons (the default), and comment at the end of main that the non-daemon threads, and hence the program, may still run after main has completed.
Edited by: jverd on Oct 21, 2008 9:27 AM

Similar Messages

  • LabVIEW closes while VI's are still running in the background

    I have created a large application that is split between VB 6 and LV 6.1. The LabVIEW portion runs in the background, except that the VB portion can request that a LabVIEW user interface be presented on demand. Any time after this LabVIEW user interface has been opened and closed, opening and closing another application (or even just hiding a top-level window in another application) will cause LabVIEW to close, taking my background processing with it.
    If the LabVIEW code is running as source code, LabVIEW prompts me before closing. However, when the LabVIEW code is running as an executable (.exe), the executable closes without prompting in this circumstance.
    The scenario can be reproduced with a standard LabVIEW sample program. Proceed as follows:
    1) Open VBToLV.vbp (the example program distributed with LabVIEW 6.1).
    2) Start the VB program running.
    3) Press the Launch LabVIEW button on the user interface of the VB program.
    4) Enter an expression in the text box provided.
    5) Select Display VI Front Panel.
    6) Press the Run VI button.
    7) Close the VI front panel by clicking its "X" button.
    8) Open any handy application, such as Windows Explorer or Notepad.
    9) Close this most-recently-opened program.
    10) The LabVIEW Exit screen appears.
    11) Exit LabVIEW.
    12) Press the Run VI button.
    13) An error occurs because LabVIEW has closed.
    If the LabVIEW code had been built into an executable and called accordingly, there would have been no LabVIEW exit screen. The executable would have just exited silently.
    This is not the way a COM server is supposed to behave. The VB program is still holding a valid reference to the server and it should remain open.
    It appears that LabVIEW is monitoring the total number of top-level windows that are open. I suppose that this is how LabVIEW figures out when its own FP windows have been closed. In this case, it doesn't notice that all of its windows have been closed until some other window closes.
    I have a work-around, but it's ugly.
    Ron Martin
    Balance Technology Inc.

    Hi,
    Perhaps you use references to windows in LabVIEW. If you get those
    references with a full path (e.g. c:\code\subvis\vi1.vi), this will work
    while in LabVIEW environment. But when an application is build, this will
    fail, because the vi is no longer there. Try using the name in a string
    instead (the OpenVIReference is polymorphic) with only the name of the vi in
    it (e.g. vi1.vi).
    There are some other isues that change when building an application. Most of
    them are paths that change, and references that fail to open because of
    them.
    Regards,
    Wiebe.
    "cpuwzd" wrote in message
    news:[email protected]...
    > I have created a large application that is split between VB 6 and LV
    > 6.1. The LabVIEW portion runs in the background, except that the VB
    > portion can request that a LabVIEW user interface be presented on
    > demand. Any time after this LabVIEW user interface has been opened
    > and closed, opening and closing another application (or even just
    > hiding a top-level window in another application) will cause LabVIEW
    > to close, taking my background processing with it.
    >
    > If the LabVIEW code is running as source code, LabVIEW prompts me
    > before closing. However, when the LabVIEW code is running as an
    > executable (.exe), the executable closes without prompting in this
    > circumstance.
    >
    > The scenario can be reproduced with a standard LabVIEW sample program.
    > Proceed as follows:
    >
    > 1) Open VBToLV.vbp (the example program distributed with LabVIEW 6.1).
    > 2) Start the VB program running.
    > 3) Press the Launch LabVIEW button on the user interface of the VB
    > program.
    > 4) Enter an expression in the text box provided.
    > 5) Select Display VI Front Panel.
    > 6) Press the Run VI button.
    > 7) Close the VI front panel by clicking its "X" button.
    > 8) Open any handy application, such as Windows Explorer or Notepad.
    > 9) Close this most-recently-opened program.
    > 10) The LabVIEW Exit screen appears.
    > 11) Exit LabVIEW.
    > 12) Press the Run VI button.
    > 13) An error occurs because LabVIEW has closed.
    >
    > If the LabVIEW code had been built into an executable and called
    > accordingly, there would have been no LabVIEW exit screen. The
    > executable would have just exited silently.
    >
    > This is not the way a COM server is supposed to behave. The VB
    > program is still holding a valid reference to the server and it should
    > remain open.
    >
    > It appears that LabVIEW is monitoring the total number of top-level
    > windows that are open. I suppose that this is how LabVIEW figures out
    > when its own FP windows have been closed. In this case, it doesn't
    > notice that all of its windows have been closed until some other
    > window closes.
    >
    > I have a work-around, but it's ugly.
    >
    > Ron Martin
    > Balance Technology Inc.

  • Access data from a SubVi to the MainVi while the SubVi is still Running

    I want to pass some Boolean/String from a subvi to the main vi while the subvi is still running. 
    I understand that it could be done using queue/ notifier. I do not want to use global variables. I looked at different examples but failed to figure out how to do it.
    I was trying to make an example by looking at an example from Labview about notifier. 
    Can anyone please help me with this code and guide me to the correct way.
    Thanks.
    Attachments:
    mainVi.vi ‏9 KB
    SubVi.vi ‏11 KB

    Hi babu726,
    I have included a revised MainVi.vi and SubVi.vi for you. I had to modify the SubVi to get it to be called by the MainVi. I also included a disabled diagram structure with the code just copied and pasted in, since your code does not seem modular. Hopefully this helps!
    Regards,
    Michelle G
    Applications Engineering
    National Instruments
    Attachments:
    SubVi.vi ‏11 KB
    mainVi.vi ‏16 KB

  • Forcing program to close, I am deleting a lot of files from my trash but it stopped working about 1/2 way through (1650 files left) so I tried to reboot but it won't let me because a the program is still running which I can't close.

    Forcing program to close, I am deleting a lot of files from my trash but it stopped working about 1/2 way through (1650 files left) so I tried to reboot but it won't let me because a the program is still running which I can't close (stuck at 1650 files to go). So it allowed me to click cancel now it says "stopping" for 3hrs now. Is there anyway to force the MacBook Air (new model) to close as you can't remove the battery?

    Press and hold the power button until the Mac turns itself off. This force-shutdown should be done only after you've exhausted other options (you seem to have done so).
    Wait at least 60 seconds.
    Then press the power button to start up the Mac. It will take a little longer to start up because it will perform additional self-tests on the first boot after a forced shutdown.
    Once the bootup is complete, you should be able to delete the trash. Hold down the option key while choosing to empty the trash, which will automatically delete "locked" items.

  • After exiting proxifier software while web pages are still open in firefox, I could not open any web pages unless firefox is restarted. Plz help me.

    I have a problem with Firefox when using Proxifier software. When proxifier is runing and I'm browsing web pages with firefox all things is OK. But after exiting proxifier while web pages are still open in firefox, I encounter a problem. In spite of the internet is still connected but my firefox could not open any web pages unless firefox is restarted.
    You are kindly requested help me how to solve this problem not to restart firefox.

    Hi,
    [http://proxifier.com/ Proxifier] seems to be a transparent proxy. So you could try setting '''No proxy''' in Firefox '''Tools''' ('''Alt''' + '''T''') > '''Options''' > [https://support.mozilla.org/en-US/kb/advanced-settings-browsing-network-updates-encryption Advanced] > '''Network''' > '''Settings'''.
    PS: A quick way to restart Firefox is to press [https://developer.mozilla.org/en-US/docs/Tools/GCLI '''Shift''' + '''F2'''], type '''restart''', and hit '''Enter'''.
    [https://support.mozilla.org/en-US/kb/Options%20window Options]

  • I installed iWork11 but the '09 versions of the software are still running--and the default. What do I need to do to get the '11 versions working?

    I installed iWork11 but the '09 versions of the software are still running--and the default. What do I need to do to get the '11 versions working?

    It's very simple. If you want to use iPhoto, just let it manage things as it does. Other than that: Export from iPhoto and delete the image from iPhoto. That will remove the master and all versions.
    If space is an issue... use an external disk.
    Don't change anything in the iPhoto Library Folder via the Finder or any other application. iPhoto depends on the structure as well as the contents of this folder. Moving things, renaming things, deleting them or otherwise making changes will prevent iPhoto from working and could even cause you to damage or lose your photos.
    Regards
    TD

  • Audio playback stops while the video is still running!!!

    Hi friends...
    I use my final cut for online streaming... and usually make a timeline for 11-12 hrs and run it in loop... everything worked fine all these years... but offlate we have been having problems with the audio playback... THE PROBLEM IS... while the timeline is still running and we can see the video on the screen the audio stops... but it stops after a few hours not at the time we start the timeline... as of now all we do is tap the spacebar twice to stop and start play again and it works again... but i would want a more permanent solution if anyone could help me out...
    thanks
    Anshu

    Hi,
    Yes, using all the default out of the box Coherence POF support, you would need to restart the cluster to pick up any changes.
    Do you really need the Java classes on the server side? Depending on what server side functionality you are using you might not actually need Java representations of the .Net classes. For example, if these are you entities that are being cached and you are never calling code that deserialises them, then there is no need for Java classes.
    You could potentially write your own implementation of a POF Serializer (PofContext) that is used on the server side that can dynamically add and change classes.
    JK

  • Add/Update user-type (Custom types) .jar while the server is still running

    Hi!
    I'm connecting from a .NET App to the cache server so I have to create the java version of my user-types, I compile this classes into a jar file and I send that in to the class path when the server starts:
    %JAVA_EXEC% -server -showversion %JAVA_OPTS% %SYS_OPTS% -cp "config;_*lib\custom-types.jar*_;%COHERENCE_HOME%\lib\coherence.jar" com.tangosol.net.DefaultCacheServer %1
    What happen if I want to add a new custom type while the serer is still running ? Do I just have to replace the jar file ? is this going to be reflected on the server since it is already running.
    If I have to stop the server then what should I take in to account to avoid data losing ?
    Thanks for your help in advance.

    Hi,
    Yes, using all the default out of the box Coherence POF support, you would need to restart the cluster to pick up any changes.
    Do you really need the Java classes on the server side? Depending on what server side functionality you are using you might not actually need Java representations of the .Net classes. For example, if these are you entities that are being cached and you are never calling code that deserialises them, then there is no need for Java classes.
    You could potentially write your own implementation of a POF Serializer (PofContext) that is used on the server side that can dynamically add and change classes.
    JK

  • Chart builder finish but some threads are still alive ?!?!?!?

    Hello all,
    I'm using oracle chart builder for presenting data in my
    application. I use it after supplying its data for gif file
    generation. The chart is stacked bar but I don't think this is the
    problem.
    The problem is that it generates the gif file successfully but my
    application is still running after the main method is finished, I
    debugged it and I found about three threads are up:
    Thread[AWT-EventQueue-0]
    Thread[SunToolkit.PostEventQueue-0]
    Thread[AWT-Windows]
    I doubted my code - but I'm taking it copy paste from developer's
    guide - and I debugged another Java file from a sample that comes with
    the kit and the same problem happened ?!?!?
    Does anyone know y?
    I saw lots of SunToolkit.PostEventQueue-0 & AWT-EventQueue-0 problems, but I don't find matching my situation, nearly some mentioned problem in native threads or something, but I think the problem is related to AWT more
    I used in testing both Oracle JDeveloper 9i release 3, and IBM
    WebSphere Studio Application Developer 4.0.3 ( both JDK 1.3)
    Thankx

    I used ctrl-break to display all threads working and the following was printed:
    "Thread-6" prio=5 tid=0x2349f8 nid=0x9e0 waiting on monitor [0..0x6fb38]
    "AWT-Windows" prio=5 tid=0x8a07e50 nid=0x894 runnable [0xba9f000..0xba9fdc4]
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    "SunToolkit.PostEventQueue-0" prio=5 tid=0x8a07878 nid=0x88 waiting on monitor [
    0xba5f000..0xba5fdc4]
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Unknown Source)
    at sun.awt.PostEventQueue.run(Unknown Source)
    "AWT-EventQueue-0" prio=7 tid=0x8acbe30 nid=0x980 waiting on monitor [0xba1f000.
    .0xba1fdc4]
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Unknown Source)
    at java.awt.EventQueue.getNextEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    "Thread-4" daemon prio=5 tid=0x8ad6be8 nid=0x90c waiting on monitor [0x99bf000..
    0x99bfdc4]
    at java.lang.Thread.sleep(Native Method)
    at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:95)
    "Thread-3" daemon prio=5 tid=0x8ad6aa0 nid=0x8c0 waiting on monitor [0x8f5f000..
    0x8f5fdc4]
    at java.lang.Thread.sleep(Native Method)
    at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:95)
    "Thread-2" daemon prio=5 tid=0x8a37008 nid=0x900 waiting on monitor [0x8f1f000..
    0x8f1fdc4]
    at java.lang.Thread.sleep(Native Method)
    at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:95)
    "Thread-1" daemon prio=5 tid=0x8b63c0 nid=0x948 waiting on monitor [0x8edf000..0
    x8edfdc4]
    at java.lang.Thread.sleep(Native Method)
    at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:95)
    "Thread-0" daemon prio=5 tid=0x8b64a8 nid=0x9c0 waiting on monitor [0x8e7f000..0
    x8e7fdc4]
    at java.lang.Thread.sleep(Native Method)
    at org.apache.log4j.helpers.FileWatchdog.run(FileWatchdog.java:95)
    "Signal Dispatcher" daemon prio=10 tid=0x7fdf28 nid=0x72c waiting on monitor [0.
    .0]
    "Finalizer" daemon prio=9 tid=0x7fabb8 nid=0x560 waiting on monitor [0x8c5f000..
    0x8c5fdc4]
    at java.lang.Object.wait(Native Method)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
    "Reference Handler" daemon prio=10 tid=0x7f9368 nid=0x9a8 waiting on monitor [0x
    8c1f000..0x8c1fdc4]
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Unknown Source)
    at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
    "VM Thread" prio=5 tid=0x23f638 nid=0xa28 runnable
    "VM Periodic Task Thread" prio=10 tid=0x8a4f48 nid=0x92c waiting on monitor

  • How to disable a main vi while a sub-vi is running?

    I have a vi that calls up two sub-vi's using menu buttons. It is done using a typical state machine setup. When the first sub-vi is running, the main vi is disabled until either the OK or Cancel buttons are selected on the sub-vi. When the second vi is running, the main vi remains sensitive to mouse clicks and jams up the system. How do I set the second vi so that the main vi is disabled until the second vi is closed?
    (Apparently the first vi is set up properly with dumb luck.)
    I noticed that the first vi has the dark box around the OK button which makes it work off of the enter key without having to use the mouse. The second vi does not. Does this have anything to do with the above problem? If no
    t, how is the OK button configured like the first vi?
    Property nodes does not seem to be the issue. Property nodes are only used for system initialization in this application.
    I am using LabView v6.0, full development.
    Thanks,
    --- Dave Johnson
    --- [email protected]
    --- Practical Technologies

    Hi,
    There is a solution with VI server. See attachement saved for LabVIEW 6.0.
    I hope it will be helpful.
    Attachments:
    call_subvis.zip ‏24 KB

  • Messaging has stopped working completely while clalls etc. are still fine. What do I do?

    messages carked it what's the go ? just says message failure

    Known problem:
    IOS 6 App store crash: Apple Support Communities

  • How to let the user know the application is still running during SQLite reads

    I'm using an SQLite database to read and write to my application. In some places it has to do very large reads and writes and the application comes to a standstill for like 10 seconds while this is happening. I've tried calling showBusyCursor(), but it only works if I call that function and then set a timer to execute the sql query. But the busy cursor also freezes once the connection starts.
    Why doesn't the showBusyCursor work during this time? Are there any other things I can do to the application to ensure the user that it is not frozen and just processing?

    Keep in mind that I haven't actually implemented this yet, but my path is headed right in that direction in the next few days. From wh
    at I have read you can access the database in two modes: synchronous and asynchronous. From your description it sounds like you are accessing the database in synchronous mode, which will stop the application thread until the database thread is completed.
    To get around that limitation you will want to run your database accesses in asynchronous mode, so that the application will continue running while the database is being accessed. What you do then is implement a listener on the database that will call a function that will hide the waiting cursor or image. Then you start the waiting indicator in the application. Once the database is done, it will trigger your listener and remove the waiting indicator, allowing the user to once again interact with your app.
    Hope this helps!
    ~Mike

  • How do I get values into a vi from a subvi while the subvi is still running within the vi?

    Hello
    This is my problem. I have a subvi that runs an experiment. At different point in the experiment different instruments are on or off and I have a boolean array display this info. It is updated at various points of the experiment via a local variable. That works fine. Here is the problem though. I run that subvi from a main vi program (that runs it several times for several experiment cycles). I would like to pass the status of that array onto the mainvi to display there too. The problem is that the array in the main vi is not updated until the subvi is done running and thus displays only the array status at end of experiment (instead of changing
    as the status changes within the subvi). I tried using a global variable to write to it in the subvi every time there is an update, and read from it in the mainvi, but that doesn't work, it still displays just the status at the end of the subvi execution. Does anyone know how to make this work, or if there is a workaround this? Thanks.

    If you have LabVIEW 6i, you can update indicators of a calling VI from
    a SubVI, while the subVI is running.
    In your case you need
    1) an indicator on the main VI panel to display the boolean array
    2) to pass a reference to that indicator to the subvi when you call it
    3) to use this reference in the subVI, connect a property node to it and
    write the values to be displayed to the 'value' property of this node
    If you don't have version 6, you can write the values to be displayed to
    a global and display this global in the main VI from within a while loop
    which must run in the main VI in parallel to the running subVI.
    It's more complicated, since you need a mechanism to gracefully shut
    down the while loop after subVI finishes. You could do this with
    another global control boolean which is not displayed but just connected
    to the repeat terminal of the while loop. Don't forget to put a 'Wait' of,
    say, 50...100 msec in that while loop.
    -Franz
    zkajan schrieb:
    > Hello
    > This is my problem. I have a subvi that runs an experiment. At
    > different point in the experiment different instruments are on or off
    > and I have a boolean array display this info. It is updated at
    > various points of the experiment via a local variable. That works
    > fine. Here is the problem though. I run that subvi from a main vi
    > program (that runs it several times for several experiment cycles). I
    > would like to pass the status of that array onto the mainvi to display
    > there too. The problem is that the array in the main vi is not
    > updated until the subvi is done running and thus displays only the
    > array status at end of experiment (instead of changing as the status
    > changes within the subvi). I tried using a global variable to write
    > to it in the subvi every time there is an update, and read from it in
    > the mainvi, but that doesn't work, it still displays just the status
    > at the end of the subvi execution. Does anyone know how to make this
    > work, or if there is a workaround this? Thanks.
    Franz Josef Ahlers
    Section Semiconductor Devices
    Physikalisch-Technische Bundesanstalt
    Bundesallee 100
    D-38116 Braunschweig
    phone: (+49) 531 592 2410
    fax: (+49) 531 592 2405

  • What is the best way to pass a controllin​g signal out of a sub vi or more than one layer of for loop, while the sub vi or for loops are still running?

    I have a vi that runs through two for loops and a while loop, then after a certain number of iterations on the inner while loop it is supposed to pass a trigger to a case stucture to start measurement. I have tried using a local variable attached to a boolean control which in turn is attached to the true case of the case structure involving the measurement sub vi. What is happening is that the boolean control will light on the front panel at the correct # of iterations in the while loop, as if true, but the measurement is not taken, and the boolean control never goes back to false. It remains lit. Am I u
    sing the local variable incorrectly? If so, where am I going wrong.
    Attachments:
    GL_Flicker.vi ‏118 KB
    Take_Measurements.vi ‏147 KB

    Hello planar,
    There are multiple ways to pass control information between loops and VIs and each one has its place. For simple VIs like your example, a local variable will be fine.
    The main reason the subVI is not running is that the case structure is not continuously polling the Boolean control. This is because the case structure is not inside a loop and as such will only read the Boolean value once and execute once. Encasing the case structure and control inside the while loop should solve the issue of the subVI not running.
    You may find the following links of help in creating more robust and advanced VI architectures.
    Application Design Patter
    ns: Master/Slave
    LabVIEW Application Design Patterns
    Keep up to date on the latest PXI news at twitter.com/pxi

  • Exiting PP closes but, program still running, danger Will Robinson

    This was an issue on the demo version of Production Pro which expired and since then I've loaded Master Suite demo to continue until my hard copy of Production Pro arrives.
    The issue is that initially, I was unaware of the program not closing down in backgorund and after a few in and out episodes would get a hard boot safety shut down because resources were maxed and the CPU was getting to critical mass heat, shutting off abrubtly.
    I reported it to Adobe in the sky and just wondered of anyone else has had this happen? Or could point to what is causing the ghosting allocation to stay active?
    It went on for a couple of weeks and was not the best Mojo for the two SATA drives but we eventually isolated why the laptop was overheating.
    The new demo is doing the same thing so I hit control alt delete to close the background manually after exiting the program normally.
    The machine:W7P,  i7, 500 GB 5400 SATA, 2TB eSATA 7200, below the Mercury minimum 749 with an 500mbs GeForce, 380M.
    I hope the hard copy will overcome this but forwarned is forebearance.
    Some ultra bug no doubt that will be sorted out down the line.
    Thanks in advance for any noodeling,
    Rob

    When you're running the demo, you're running version 5.0.0--the initial release. There have been three feature-and-bug-fix releases since then. You'll be able to update to the last released version once you've registered the software. Though I can't say for certain, I suspect this issue would go away once you're running 5.0.3 (current version).
    Post back after you've installed that, if it doesn't correct the problem.

Maybe you are looking for

  • I forgot my iphone passcode, it's disabled now, and I can't restore??

    Hey guys, I've had an iphone for about 3 weeks. All of a sudden today I couldn't remember the lock code. Stupid I know! Anyhow I panicked and entered what I thought was the password way too many times. In short, it's now disabled now. I read on how t

  • Mail not sending while traveling

    When I travel with my powerbook and use mac mail, none of my outgoing servers work. Shouldn't my me.com account work anywhere my mail works? Also, my comcast acct doesn't work, but it's a secondary account, so not as important as my 'me' account. I'v

  • How to activate / disactivate a servlet with a java client ?

    I would like to know how to activate or disactivate a servlet with a java client or an applet ? Thanks...

  • Calling an Unix command on Remote sun Server in a Java Code

    Hello All I have an Java Application which is run on windows server (I) I have another Sun Server (II) I want to call an unix command on server(II) from java application which is on server(I) I am using Samba Server in order to share files between Wi

  • Tranport portal content from SP14 to SP18

    Hello, Is it possible and advisable to transport portal content (iviews, roles, etc) from a portal on EP6 SP14 to EP6 SP18?  Do I need to manually move configuration from one portal to the other?  What are my options? Thank you for feedback. Kevin