Is the main program seen as a separate thread ?

I wanted to stop a GUI based program opening too fast because the splash screen wasn't seen for long enough.
So I tried to use the Thread and Runnable classes within the GUI constructor.
By trying different things, I got it to do as I wanted : a delay of 10 seconds before showing the program's GUI.
But I don't understand why main is not seen as a separate thread and thus continue to make itself visible no matter what the delayThread status may be.
// Constructor:
public Hotel (int numberIn)
         // Create the time delay thread so that users may enjoy the splash !
         delayThread = new Thread(this);
         delayThread.run();
         // Initialise the number of rooms and the GuestList :        
        noOfRooms =  numberIn;
        guests  = new GuestList(noOfRooms);
        // Graphics settings:     
        setTitle("Hotel");     
        setLayout(new FlowLayout());
       // etc. etc.
       // etc. etc.
       setVisible(true);
    // A run method to delay the program opening:
    public void run()
         try
              delayThread.sleep(10000);
         catch(InterruptedException ie)
              ie.printStackTrace();
    }Now, maybe a better way to do this would be to move the setVisible statement from the constructor to the run method.
Maybe there is an even better mechanism for producing a delay in a program's opening.
But I'm still curious as to why the main thread was delayed by a delay in what is really an entirely separate thread.
Any ideas ?
Edited by: KonTiki on 16-Feb-2013 13:10
Edited by: KonTiki on 16-Feb-2013 13:19
Edited by: KonTiki on 16-Feb-2013 13:20
Edited by: KonTiki on 16-Feb-2013 13:21
Edited by: KonTiki on 17-Feb-2013 09:16

Well, first of all calling a Thread object's run() method just runs the code in the same thread. It doesn't start a new thread -- that's what calling the start() method does.
And the Thread.sleep() method is a static method, meaning "Make *this* thread sleep for X milliseconds". So calling it on another Thread object doesn't cause that thread to sleep, it causes the current thread to sleep.
I suggest you should go through the concurrency tutorial from Oracle because you seem to be programming by guesswork here.

Similar Messages

  • How can I allow a sub-vi to run independent of the main program once it has been called while still sending data to the sub-vi

    I have a main program where I call a sub-vi. In this sub-vi, there is a while loop that is used to wait for commands in the sub-vi. While the while loop is running, I cannot continue with normal operation of the main program. I would like get the sub-vi to run independently once it has been called, but not hold up the main program. As well, I need to still be able to send data to the sub-vi

    One way is to use VI Server, which has been mentioned by others. This will allow you to start another VI (by name) and run it entirely independently of the calling VI. This is a good way to start various independent VIs from a main menu, for example. None of the VIs thus called need have any connection to the others.
    Another way it to have the SubVI in a separate while loop on the calling VI's BD. Then, use a local var to start this sub VI from the main loop. The calling VI sets a local START bit and continues running. The sub VI's while loop watches for this START bit to go true, and then runs the Sub VI. The advantage here is that one can more easily pass arguments to the SubVI when it is started, using local vars, which are preferable to globals. Once the Su
    bVI is running, however, you must use a global Stop Bit, set in the calling VI, to stop it when the calling VI exits, or the calling VI will hang up, waiting for the Sub VI to close and exit its while loop.
    If you need an example of this, email me. ([email protected]). I can also recommend Gary W. Johnson's excellent book which discusses this. ("LabVIEW Graphical Programming", 2nd Ed).
    Note: Where possible, I try to call a subvi from within the main VI, wait till it is done, then continue. It avoids the use of locals & globals, and results in cleaner code, with fewer "race" conditions. However, the main VI stops until the subVI is done, hence one should make the subVI modal.

  • How to pass the caught exception in Thread.run back to the main program?

    I have following three Java files (simplified from a real world application I am developing, see files at the end of this posting):
    1. ThreadTest.java: The main program that invokes the Manager.run()
    2. Manager.java: The manager that creates a thread to execute the Agent.run() for each agent
    3. Agnet.java: The run() method can throw Exception
    My goal is twofold:
    1. To execute the run() method of an Agent in a thread (the reason for this is there are many Agents all managed by a Manager)
    2. To catch the exception thrown by Agent.run() in the main program, ThreadTest.main() -- so the main program can alert the exceptions
    My problem:
    Bottomline: I cannot pass the exception thrown by Agent.run() in the Thread.run() back to the main program.
    Explanation:
    The signature of Thread.run() (or Runnable.run()) is
    public void run();
    Since it does not have a throws clause, so I have to try/catch the Agent.run(), and rethrow a RuntimeException or Error. However, this RuntimeException or Error will not be caught by the main program.
    One work-around:
    Subclass the ThreadGroup, override the ThreaGroup.uncaughtException() methods, and spawn the threads of this group. However, I have to duplicate the logging and exception alerts in the uncaughtException() in addition to those already in the main program. This makes the design a bit ugly.
    Any suggestions? Am I doing this right?
    Thanks,
    Xiao-Li "Lee" Yang
    Three Java Files:
    // Agent.java
    public class Agent {
    public void run() throws Exception {
    throw new Exception("Test Exception"); // Agent can throw execptions
    // Manager.java
    public class Manager {
    public void run() throws Exception {
    try {         // <===  This try/catch is virtually useless: it does not catch the RuntimeException
    int numberOfAgents = 1;
    for (int i = 0; i < numberOfAgents; i++) {
    Thread t = new
    Thread("" + i) {
    public void run() {
    try {
    new Agent().run();
    } catch (Exception e) {
    throw new RuntimeException(e); // <=== has to be RuntimeException or Error
    t.start();
    } catch (Exception e) {
    throw new Exception(e); // <== never got here
    // ThreadTest.java
    public class ThreadTest {
    public static void main(String[] args) {   
    try {
    Manager manager = new Manager();
    manager.run();
    } catch (Throwable t) {
    System.out.println("Caught!"); // <== never got here
    t.printStackTrace();

    The problem is, where could you catch it anyway?
    try {
    thread.start();
    catch(SomeException e) {
    A thread runs in a separate, er, thread, that the catch(SomeException) isn't running within. Get it?
    Actually the Thread class (or maybe ThreadGroup or whatever) is the one responsible for invoking the thread's run() method, within a new thread. It is the one that would have to catch and deal with the exception - but how would it? You can't tell it what to do with it, it (Thread/ThreadGroup) is not your code.

  • Issue in connecting sub VI programs through the main program

    Sir/Madam,
                       I have made a few sub VI  programs of 'Keithley 2400', but I am having problem in connecting them together through the main program. Actually the created sub VI programs are not showing  any activation button when I connect 'action.vi' file in 'read.vi' file (attachted). 
    Please give suggestions.
    Regards
    Yachika Manglik
    Solved!
    Go to Solution.
    Attachments:
    action.vi ‏24 KB
    read.vi ‏14 KB
    write.vi ‏24 KB

    Hello
    Thanks for your suggestion.
    I have successfully implemented connections in my code according to your given suggestion .
    Now I am facing problem to link a file named 'control1.ctl'(attached) that I have made for selecting option 'select type of action' and need to add' control1.ctl' in  'read.vi' file. It is showing  following error( below).
    Error: " required input ' GPIB action' is not wired.
                     OR
               "Enumeric conflict"
    So can you please suggest how this error can be removed?
    Attachments:
    Control 1.ctl ‏5 KB
    read.vi ‏13 KB

  • PeopleCode - commit/rollback subprogram without committing or rolling back the data in the main program

    Hi,
    Is there a way in PeopleSoft/PeopleCode to do some database transactions in a subprogram (peoplecode function or method in Application Package) and commit that transaction without committing the things that are happening in the main program?
    you can compare it with a "autonomous_transaction" ( http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/autonotransaction_pragma.htm ) / ( http://oracle-base.com/articles/misc/autonomous-transactions.php )
    or with what is happening in the database when using "GetNextNumberWithGapsCommit"
    or what happens when you turn on the logging in PeopleTools > Integration Broker > Integration Setup > Routingyou put a button on a page and write some PeopleCode on the FieldChange
    you first do a update statement with sqlexec
    you call the webservice (data is inserted in the PSIBLOGDATA and PSIBLOGINFO and committed)
    you generate a "Error" in PeopleCode
    => result: the update from the sqlexec is not committed, but the logging data (PSIBLOGDATA and PSIBLOGINFO) IS committed
    Kind regards, Bart

    Hi,
    Please take a look at the javadoc for the following BC4J API:
    ApplicationModule.passivateStateForUndo(String, byte[], int)
    ApplicationModule.activateStateForUndo(String, int)
    These APIs may not however be used to manage a DB savepoint -- they assume that all state is managed by the BC4J transaction.
    Hope this helps,
    JR

  • DUMP in program webdynpro  ASSERTION_FAILED  The main program was "SAPMHTTP

    We have a program in webdypro and yesterday we had this dump,but nobody can me tell wath it is mean?.
    Can someone help me? Thanks Flavia
    Texto breve
        The ASSERT condition was violated.
    Anál.errores
        The following checkpoint group was used: "No checkpoint group specified"
        If in the ASSERT statement the addition FIELDS was used, you can find
        the content of the first 8 specified fields in the following overview:
        " (not used) "
        " (not used) "
        " (not used) "
        " (not used) "
        " (not used) "
        " (not used) "
        " (not used) "
        " (not used) "
    Notas para corregir errores
        Probably the only way to eliminate the error is to correct the program.
        If the error occures in a non-modified SAP program, you may be able to
        find an interim solution in an SAP Note.
        If you have access to SAP Notes, carry out a search with the following
        keywords:
        "ASSERTION_FAILED" " "
        "CL_WDR_VIEW_ELEMENT_ADAPTER===CP" or "CL_WDR_VIEW_ELEMENT_ADAPTER===CM01L"
        "DISPATCH_EVENT"
        If you cannot solve the problem yourself and want to send an error
        notification to SAP, include the following information:
        1. The description of the current problem (short dump)
           To save the description, choose "System->List->Save->Local File
        (Unconverted)".
        2. Corresponding system log
           Display the system log by calling transaction SM21.
           Restrict the time interval to 10 minutes before and five minutes
        after the short dump. Then choose "System->List->Save->Local File
        (Unconverted)".
        3. If the problem occurs in a problem of your own or a modified SAP
        program: The source code of the program
         In the editor, choose "Utilities->More
      Utilities->Upload/Download->Download".
      4. Details about the conditions under which the error occurred or which
      actions and input led to the error.
    Usuario y transacción
        Client.............. 300
        User................ "CTACTEPROV"
        Language Key........ "S"
        Transaction......... " "
        Program............. "CL_WDR_VIEW_ELEMENT_ADAPTER===CP"
        Screen.............. "SAPMHTTP 0010"
        Screen Line......... 2
        Information on Caller ofr "HTTP" Connection:
        Plug-in Type.......... "HTTP"
        Caller IP............. "10.10.10.90"
        Caller Port........... 8001
        Universal Resource Id. "/"
    Info posición de cancelación
        Termination occurred in the ABAP program "CL_WDR_VIEW_ELEMENT_ADAPTER===CP" -
         in "DISPATCH_EVENT".
        The main program was "SAPMHTTP ".
        In the source code you have the termination point in line 5
        of the (Include) program "CL_WDR_VIEW_ELEMENT_ADAPTER===CM01L".

    Hello,
    We implement some notes and so far not returned the problem. I do not know if it solved the problem but maybe help you.
    Nota 1522829
    Nota 1070532
    Flavia

  • How to get variant of SUBMIT program to the main program.

    Hi!
    In my ZFRFI00R_PRINT_DOCUMENTS program i am using
    SUBMIT zfrfi01r_alv_fi_document
    using SELECTION-SET sp_vari
    with p_comp  = gw_bkpf_key-bukrs
    with p_year    = gw_bkpf_key-gjahr
    with p_doc    =  gw_bkpf_key-belnr
    and return.
    So in the main program i created one layout field to get the what are all the layouts in the SUBMIT program.
    I am using FMs 'REUSE_ALV_VARIANT_DEFAULT_GET' , 'REUSE_ALV_VARIANT_F4'  to get default layout from the SUBMIT program.
    It is not showing the layouts which are in the SUBMIT program when i press F4 in the layouy input field in the selection screen of the main program.
    Can anyone help in this regard?
    Thank you in advance for ur help.
    Regards,
    Raj

    Hi,
    IN the disvariant parameter are you populating the correct program name..meaning the submitted program name..
    Thanks,
    Naren

  • How to pause the main program and resume it the first sequence again?

    I am building the main program. How do I pause it in case of activated emergency button or errors? Once the button is deactivated and errors are corrected, I need to resume it again at the first sequence, like reset, not close the program. How to do it?

    Hello astroboy,
    you have to program it...
    A construct like "if not(error) then continue else startover" could help. Also the error cluster and its use in (nearly) all communication VIs can help you. And it could help to connect such error cluster to a case structure...
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • The main program SAPLZOTMRMK must be generated.

    Hi Experts,
    We have Implemented one BADI 'INVOICE_UPDATE'. When ever I try to keep an break point it throws an msg saying 'The main program SAPLZOTMRMK must be generated'. Could you please let me know how to overcome this issue.
    Regards,
    Ravi Kasnale

    Go to SE38, enter program SAPLZOTMRMK, press Activate button

  • Getting the main program or tcode from child tcode

    Hi
    I execute a tcode1 . And while in that tcode1, I select the sub menu in the help menu. This sub menu is a custom one with a tcode2. Tcode2 calls a program. I would like to get tcode1 when I am in this progam. Somehow i get only Tcode2. Is there a way to get tcode1 which is the main tcode ?  
    Thanks
    Bindu

    SY-CPROG
    The name of the calling program in an external routine, otherwise the name of the current program.
    based on that you can hit TSTC table and get the transaction code for that program... "some includes does not have T codes!"

  • Can i install 'extra audio content' after i have installed the main program?

    hello all!
    i need to install the 'extra audio content' that comes with Logic, as i didnt include them when installing in the first place.
    how do i go about doing this?
    i mainly need all the different presents and chanel strips, not so bothered about the loops.
    would appreciate any help.
    many thanks

    That's what usually happens - you download and install Logic first and the additional content is downloaded from within the application (under the Logic Pro menu at the top left). Unless you have a blazing internet connection, you're probably better to download one set at a time - you can delete stuff that you don't want, if necessary or move loops to another drive etc..unfortunately the setup programs don't allow for installation directly to another drive.

  • Accessing Classes From the Main Program:

    Hey Guys if you want to take a crack at this: I'm not sure how to exaclty get the classes read into my program and stuff. So I dunno if not don't worry. And Also ther'es no need to insult me.
    * just copy this into any editor
    import java.io.*;
    import java.text.*;
    class Liststuff
    public class Node
    char info;
    Node next;
    public class listException extends Exception
    public listException(String message)
    super(message);
    class Queue
    private Liststuff.Node front;
    private Liststuff.Node rear;
    public Queue()
    front = null;
    rear = null;
    public boolean isEmpty()
    return (front == null);
    public void insert(char v)
    Liststuff.Node n = new Liststuff.Node();
    n.info = v;
    n.next = front;
    if (rear == null)
    front = n;
    else
    rear.next = n;
    public char Remove() throws Liststuff.listException
    char v;
    if (isEmpty())
    throw new Liststuff.listException("Nothing in OrigQue.");
    else
    v = rear.info;
    rear = rear.next;
    return (v);
    class Stack
    Liststuff.Node top = new Liststuff.Node();
    public Stack()
    top = null;
    public void push(char v)
    Liststuff.Node n = new Liststuff.Node();
    n.info = v;
    n.next = top;
    top = n;
    public char pop() throws Liststuff.listException
    char v;
    if (isEmpty())
    throw new Liststuff.listException("Stack underflow.");
    else
    v = top.info;
    top = top.next;
    return (v);
    public boolean isEmpty()
    return (top == null);
    class Deque
    private Liststuff.Node front = new Liststuff.Node();
    private Liststuff.Node rear = new Liststuff.Node();
    private Liststuff.Node f = new Liststuff.Node();
    public Deque()
    front = null;
    f = null;
    rear = null;
    public void insert(char v)
    Liststuff.Node n = new Liststuff.Node();
    n.info = v;
    n.next = front;
    if (rear == null)
    front = n;
    else
    rear.next = n;
    public char remove(char side) throws Liststuff.listException
    char v;
    if (isEmpty())
    throw new Liststuff.listException("Nothing in OrigQue.");
    else
    f = rear;
    if (side == 'R')
    while (f.next != front)
    f = f.next;
    v = front.info;
    front = f;
    else
    v = rear.info;
    rear = rear.next;
    return (v);
    public boolean isEmpty()
    return (front == rear);
    public class Prog8
    public static void main(String args[]) throws IOException, Liststuff.listException
    String line;
    int i;
    char t;
    Liststuff s = new Liststuff();
    BufferedReader br = new BufferedReader(new FileReader("numbers.txt"));
    line = br.readLine();
    StringCharacterIterator c = new StringCharacterIterator(line);
    while (line != null)
    for (i = 0; i <= c.getEndIndex(); i++)
    Liststuff.Queue Orig = new Liststuff.Queue();
    Liststuff.Stack Evenstk = new Liststuff.Stack();
                   Liststuff.Deque Oddque = new Liststuff.Deque();
                   Liststuff.Queue Final = new Liststuff.Queue();
    t = c.current();
    char v = (t);
    c.next();
    Orig.insert(v);
    line = br.readLine();
    if ((v % 2) == 0)
    Evenstk.push(v);
    else
    Oddque.insert(v);
    Final.insert(Evenstk.pop());
    while (!Oddque.isEmpty())
    Final.insert(Oddque.remove('R'));
    Final.insert(Oddque.remove('L'));
    System.out.print("Original Sequence: ");
    while (!Orig.isEmpty())
    System.out.print(Orig.Remove());
    System.out.print("New Sequence: ");
    while (!Final.isEmpty())
    System.out.print(Final.Remove());
    }

    hi mate
    System.out.print("Original Sequence: ");
    while (!Orig.isEmpty())
    System.out.print(Orig.Remove());
    System.out.print("New Sequence: ");
    while (!Final.isEmpty())
    System.out.print(Final.Remove());
    thats you wacky code remember its insult free comments
    well here the best way to do it
    for Final.insert(Oddque.remove('R'));
    System.out.print("Original Sequence: ");
    while (!Orig.isEmpty())
    System.out.print(Orig.Remove());
    while Final.insert(Oddque.remove('L'));
    System.out.print("New Sequence: ");
    while (!Final.isEmpty())
    System.out.print(Final.Remove());
    else bla bla bla
    hope it cann hep though i dont whats is the problem
    and be clear you question.

  • How to find the name of the main program in the SM35

    Hi all,
    I have problems to find which program a batch input belongs to: may I explain myself...I can see in transaction SM35 several session names but no trace of the name of the program which is being used...I tried to find it with table APQI but no results so far. Does anyone know how can I get this information?
    Thanks a lot!

    Check table TBTCP
    Regards,
    Rich Heilman

  • Do we write classes in abap seperately from the main program

    For instance following class is designed to capture the click of hotspot and double clicks from a screen layout.  immediately I need it.Thanks everyone.
    Where should I put such a code?
    CLASS lcl_event_handler DEFINITION .
    PUBLIC SECTION .
    METHODS:
    *--Hotspot click control
    handle_hotspot_click
    FOR EVENT hotspot_click OF cl_gui_alv_grid
    IMPORTING e_row_id e_column_id es_row_no ,
    *--Double-click control
    handle_double_click
    FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row e_column es_row_no.
    PRIVATE SECTION.
    ENDCLASS.
    CLASS lcl_event_handler IMPLEMENTATION .
    *--Handle Hotspot Click
    METHOD handle_hotspot_click .
    PERFORM handle_hotspot_click USING e_row_id e_column_id es_row_no .
    ENDMETHOD .
    *--Handle Double Click
    METHOD handle_double_click .
    PERFORM handle_double_click USING e_row e_column es_row_no  .
    ENDMETHOD .
    ENDCLASS .
    FORM CREATEOBJECT.
    DATA gr_event_handler TYPE REF TO lcl_event_handler .
    *--Creating an instance for the event handler
    CREATE OBJECT gr_event_handler .
    SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .
    SET HANDLER gr_event_handler->handle_hotspot_click FOR gr_alvgrid .
    ENDFORM.
    FORM handle_hotspot_click USING i_row_id TYPE lvc_s_row
    i_column_id TYPE lvc_s_col
    is_row_no TYPE lvc_s_roid.
    READ TABLE zbficheentry_list2 INDEX is_row_no-row_id .
    IF sy-subrc = 0." AND i_column_id-fieldname = 'SEATSOCC'.
    CALL SCREEN 200 . "Details about passenger-seat matching
    ENDIF .
    ENDFORM .
    FORM handle_double_click USING i_row TYPE lvc_s_row
    i_column TYPE lvc_s_col
    is_row_no TYPE lvc_s_roid.
    READ TABLE zbficheentry_list2 INDEX is_row_no-row_id .
    IF sy-subrc = 0." AND i_column-fieldname = 'SEATSOCC' .
    CALL SCREEN 120 . "Details about passenger-seat matching
    ENDIF .
    ENDFORM .

    Hi,
    Check the link,
    Re: hotspot
    Regards,
    Azaz Ali.

  • Error in the standar program RAJAWE00

    Hi ALL
    When I try to run transaction AFAR or AJRW in the BACKGROUND the job overview shows the status as cancelled. The description says LOAD PROGRAM NOT FOUND.
    The dump points to an include LSBAL_DISPLAY_BASEF02.
    IT says
    Possible reasons:
    a) Wrong program name specified in an external PERFORM or
    SUBMIT or, when defining a new transaction, a new
    dialog module or a new function module.
    b) Transport error
    b) Transport error
    load generated program
      PERFORM load IN PROGRAM (i_s_prof_int-progname).
    point to some main fields
    ->  macro_assign:
        'G_DISPLAY'          <g_display>,
        'G_CONTEXTS'         <g_contexts>.
    Im working on SAP release 640.
    Ive tried to find some relevant notes also but none of them solve the error.
    The main programs are:
    AFAR -> RAAFAR00
    AJRW -> RAJAWE00
    The error message when I review the programs is:
    Include LAFAR$01     5     @0A\QError@
    A FUNCTION already exists with the name "ANEP_AFARECHNEN"
    Need help ....
    Thanks & Regards,
    Adrian Sanchez

    Hi
    Have you seen this note yet?
    Note 935344 - ALV list: Runtime error when you display layouts
    https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=935344&nlang=EN&smpsrv=https%3a%2f%2fwebsmp202%2esap-ag%2ede
    Hope this helps.
    Cheers,
    Gimmo

Maybe you are looking for

  • Trying to restore previous iWeb files after hard drive was reformatted.

    I had to have a clean install on my MacBook last week and had my iWeb files backed up but I'm having trouble figuring out how to import the files or restore iWeb to the way it was. Any thoughts? Or is it just another lack of support and thinking on A

  • Making your Flash teaching content as effective as possible

    Hi All, I just added a new blog post with some thoughts about how creators of flash tutorials, articles, videos, etc. could make their content more usable and discoverable for Flash learners. http://blogs.adobe.com/jayarmstrong/ I'm hoping to start a

  • Print WorkItem Specific tab

    Hello, I need to print a specific tab of the change request and service requests. but whenever i open any work item and choose to print it ,it prints all the tabs (General, activities, Results,-..including the Extension) although i only need to print

  • HT204135 Unrecognisable characters when printing PDFs

    Hello people, When printing downloaded PDFs (Electric/Gas bills etc) i cannot read them, the printing is unrecognisable. This is either direct from safari or downloaded. I am printing wireless and dont have a problem with other files when printing, t

  • Amarok can't copy ogg files to media player

    I just recently thought I could as well use Amarok to copy my music files to my Samsung YP-U1. Well it did work great for my mp3 files, it did not work for my ogg files, complaining my Samsung YP-U1 not able to play them (well, sure it can). So I end