How to run threads in background

hi everyone!
I need some hints on my problem!
I have an application with some working threads. When the user minimizes the app the app should go to the system tray and the threads should keep working.
I already know how to put an icon with popup menu in the systray. Now, how can I run the working threads in background?
Can anybody help me?
C u,
Filipe

I said that because as far I understood the following code it just creates an icon and popup menu, right?
So, when the user minimizes the app I need to kill it, create the icon and popup menu and leave the threads working.
public class SystemTrayDemo extends JFrame
     private static final long serialVersionUID = 1L;
     public SystemTrayDemo()
          JPopupMenu menu = new JPopupMenu("Menu");
          JMenuItem menuItem1 = new JMenuItem("Menu1");
          JMenuItem menuItem2 = new JMenuItem("Menu2");
          JMenuItem menuItem3 = new JMenuItem("Menu3");
          JMenuItem menuItem4 = new JMenuItem("Exit");
          menu.add(menuItem1);
          menu.add(menuItem2);
          menu.add(menuItem3);
          menu.add(menuItem4);
          menuItem4.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                    System.exit(0);
          ImageIcon icon = new ImageIcon("database.png");
          TrayIcon trayIcon = new TrayIcon(icon, "Hello System Tray", menu);
          SystemTray tray = SystemTray.getDefaultSystemTray();
          tray.addTrayIcon(trayIcon);
     public static void main(String[] args)
          try
               javax.swing.UIManager.setLookAndFeel("com.sun.java.swing. plaf.windows.WindowsLookAndFeel");
          catch(Exception e)
               System.out.println(e);
          new SystemTrayDemo();
}}

Similar Messages

  • URGENT: How to run threads in sequence?

    Dear experts, I am new to writing threads. I would like to know how to run threads in sequence? How do I know when a thread finishes its task?
    In the following code, classes Process_A(), Process_B(), Process_C() and Process_D() are subclasses of Class Thread.
    I'd like to know if I am using the join() function correctly? My intention is to wait for the previous process to finish before running the current process.
    Could anyone kindly give me some solutions on how to run the processes in sequence?
    Thanks!!
    =============================================================
    Thread process;
    Vector process_names = new Vector();
    process_names.add("a");
    process_names.add("b");
    process_names.add("c");
    for(int i=0; i<process_names.size(); i++)
    String process_name = (String) process_names.elementAt(i);
    if(process_name.equals("a"))
    process = new Process_A();
    else if(process_name.equals("b"))
    process = new Process_B();
    else if(process_name.equals("c"))
    process = new Process_C();
    else if(process_name.equals("d"))
    process = new Process_D();
    timer = new javax.swing.Timer(1000, new ProcessListener());
    timer.start();
    // ProcessListener()
    class ProcessListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    if(process!=null)
    if(process.isAlive())
    try
    process.join();
    catch(Exception ex)
    ex.printStackTrace();
    process.start();

    just look at this simple example u will get to know how to use join method
    This does exactly what u want
    class callme
    void call(String msg)
    System.out.println("["+msg);
    Try
    Thread.sleep(1000);
    catch(InterruptedException e)
    System.out.println("interrupted");
    System.out.println("]");
    class caller implements Runnable
    String msg;
    Callme target;
    Thread t;
    Public Caller(Callme targ, String s)
    target=targ;
    msg=s;
    t=new Thread(this);
    t.start();
    public void run()
    target.call9msg);
    class Synch
    public static void main(String arg[])
    Callme target=new Callme();
    Caller ob1=new Caller(target,"hello");
    Caller ob2=new Caller(target,"Synchronized");
    Caller ob3=new Caller(target,"world");
    Try
    ob1.t.join();
    ob2.t.join();
    ob3.t.join();
    catch(InterruptedException e)
    System.out.println("interrupted");
    waiting for dukes

  • Running thread in background.

    I am running a program from within a terminal and when a certain action is performed I want a new thread to start running in the background. However when I do thread.run() it still runs in the terminal. I know if you want to run a program in the background you can do program&, but what would be the similar method call?
    Thanks.

    Currently when the thread is run it holds up the
    terminal. I want to make it so I can still use the
    terminal once the thread has been started, hence
    running it in the background.I think you're confusing the issue by talking about threads here. You actually seem to be asking how to detach the process from the terminal. I'm afraid Java doesn't support this operation.
    If you want this behaviour you will have to achieve it via operating system features. If you want the process to transition from an attached to a detached mode during its execution, you will probably have to make use of JNI to achieve this. If you want it to start out (and stay) detached, you will be able to use a shell script (or on Windows the javaw command).

  • Running threads in background

    I'm developing something like a Task Scheduler for my
    application. The user will select as task and schedule
    it to run in the background at a given time. When the
    task has finished running, an email will be sent to the
    user with the results.
    So I need a Task Scheduler. My scheduler will run as a
    background process within the app server and poll the
    database for new tasks to be run. The polling will
    happen every 1 minute or so. It will pick up all the
    new tasks that are due to be run, and then start 1
    separate thread for each task. When the task is done,
    the task thread will email the results to the user.
    My question is - how do I run the scheduler thread (the
    one that polls the database) in the background? The
    thread can sleep for 1 minute and then poll again.
    The other question is - am I allowed to run Threads in
    an app server environment (someone told me I'm not
    allowed to do that, as per the J2EE Standard).
    I'm looking for a J2EE-compliant solution - one that
    can be easily shifted to any app server other than
    WebLogic.
    Thanks a lot in advance.
    Manish Jethani

    You will want to create a startup class that schedules a trigger to run every
    minute.
    Mike
    "Manish Jethani" <[email protected]> wrote:
    >
    I'm developing something like a Task Scheduler for my
    application. The user will select as task and schedule
    it to run in the background at a given time. When the
    task has finished running, an email will be sent to the
    user with the results.
    So I need a Task Scheduler. My scheduler will run as a
    background process within the app server and poll the
    database for new tasks to be run. The polling will
    happen every 1 minute or so. It will pick up all the
    new tasks that are due to be run, and then start 1
    separate thread for each task. When the task is done,
    the task thread will email the results to the user.
    My question is - how do I run the scheduler thread (the
    one that polls the database) in the background? The
    thread can sleep for 1 minute and then poll again.
    The other question is - am I allowed to run Threads in
    an app server environment (someone told me I'm not
    allowed to do that, as per the J2EE Standard).
    I'm looking for a J2EE-compliant solution - one that
    can be easily shifted to any app server other than
    WebLogic.
    Thanks a lot in advance.
    Manish Jethani

  • How to run MIDlet in background in J2ME?

    Hi Friends,
    I am new guy to J2ME and MotoRazr. I just want to run application in background while other application as normal. I am targeting MotoRazr v3xx, MIDP-2.0 & CLDC-1.0.
    In some post I found that we can use "Backgrounf: True" in JAD file, I tried this but it is not working.
    Can someone will help me?
    Thanks
    From
    [email protected]

    Thanks deep,
    But I really searched in forum .... and now also I am searching. But haven't found any solution.
    I just got some keywords like
    1) pauseApp()
    2) display.setCurrent(null)
    3) PushRegistry
    4) MIDlet without UI
    5) in JAD file "Background: True"
    6) Thread
    Can you tell me which should I use?
    My exactly problem is to Run a process in background which will trap key events while other applications are running.
    What do you do suggest?
    Thanks

  • How to Run Jar in Background process

    Hi,
    I am develop one application in java,
    I have some problem in my application,
    whats my problem is, I want to run my jar file
    in system background, that is when i was start the system
    my jar gets ready to run the application,
    Can any one please give some idea to how to run my jar in
    background task and how to start the jar when the system
    start.
    Thanks in advance,
    Regards,
    Ganesh Kumar.L

    Hi
    It has been a while since you asked your question- I hope you still need the solution. Java typically does not support this because it is platform specific. I don't know what operating system you are working on. I assume Windows. There are numerous ways to do this in Windows. The easiest is to copy the program into the startup folder. The directory is: C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Another way, less visible to the user, is to make an entry in the registry. If you place the location of the program as data in a key in HKLM\Software\Microsoft\Windows\Current\Version\Run of the registry, it will start with the system. This is hard to do in Java (for obvious reasons) however it is not impossible. You can use JNI which is really difficult to learn and hard to implement or you can use
    Process p=Runtime.getRunTime().exec({"reg.exe","add HKLM..."});This will execute the Windows utility reg.exe with the arguments provided by the second in the array of Strings. Documentation on reg.exe can be found through the command prompt. There are other ways such as modifying Autoexec.bat however they are less reliable
    Hope I helped

  • How To Run Process In Background?

    Hi,
    I'm writing a CORBA Server, and basically, I need to spawn a process in the background. The process is:
    tnameserv -ORBInitialPort 1250
    I am new to Java, and am not sure how to go about doing this. Any sample code would be appreciated.
    Thanks!

    You could use a TimerTask - a user friendly way of spawning a Thread.
    For example, the class from which you want to spawn a Thread could have the following lines: -
    Timer timer = new Timer();
    timer.schedule(new MyTimerTask(), 6000, 3000);
    ...where MyTimerTask is a class you write yourself. It must extend java.util.TimerTask and define a method with the following signature: -
    public void run()
    The run method should execute the task that you need performing in the separate Thread.
    In this example, your main class would call the run() method of MyTimerTask after a delay of 10 minutes (6000 miliis) and would then continue to call it every 5 minutes.
    Hope this helps!
    Jon

  • How to run report in background, save output to word or excel

    Hello all,
    I have a huge report that needs to be run in background and I need the report in word. When running in Dialog it takes too long and SAP times out. How do you get something to run in background and have the output in excel. I know you can go into SM37, find the spool and then forward the spool request to a local file, is there an easier way to do it? Maybe setting up some kind of to text printer since the background job always asks for the output printer. Any suggestions?
    Thanks a lot,
    Sergiy

    Hi,
    Please check the article below:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f048c590-31a4-2c10-8599-bd01fabb93d4?quicklink=index&overridelayout=true
    -Vikram

  • How to run form in Background

    Hi Experts,
    I have created a form and its print program for purchase order. they are assigned to T-code: ME22N through NACE.
    Now i need to run ME22N in both foreground and background.
    If we execute in foreground, it should display the printpreview. for that in ME22N, we have a button for print preview.
    If we execute it in background, it should generate a spool, with out any printpreview. How can we do this....?
    Please some one help me in this regard.
    Thanks in advance.

    In the IMG (SPRO) under materials management -> purchase orders -> messages - > output control -> message types -> define message types
    Set up one message type for print preview.  Set up a different message type for no print preview under fine tuned control.

  • How to run InDesign in background?

    I mean to make InDesign application invisible while processing my script?    

    Which might be a reason to find a different method than indesign.
    This kind of Policy produces 2 things:
    First: They push Mediumsized companys to work illigal or not with indesign at all if they have some special needs which will be only legal by an indesign server.
    Second: They prohibit some external Developments or releases because it would be illigal tu use it.
    Theres no way to start indesign in Background with its own api (this is not 100% for shure but 95% :-)
    It might be Possible but not by VBA or Java, there are some workarounds with VB and c++ but this is a complete different animal.
    However maybe it would be legal using somekind of passive server. Means a timejob on one Computer working a set of data in some directory or Database down. It would not be a real server since the jobs starting itself on the Workstation and not by command from another application.
    Or Make a script which runs in a loop with a time break. In case 1 you have to make your own Atomic.
    But im really not shure how legal that would be. Anyway how legal the split client and Server in the policies by adobe is another animal too.
    Its hard to determine whats a server whats not in many cases.
    lets say you send the data directly to an automated workstation to work on it - is it an Server?
    if the workstation needs a pressing button thing is it or not? In that case you can use a macro keyboard to do this - is it then a server ?
    again i dont not understand this policies since you cannot start a multhithread on indesing workstation anyway it would be unuseable for real server applications. you cannot make a hing like a webservice because its simply to slow and unstable.
    didnt solve our problems but to be honest, im shure bevore a customer with lets say 8 or 9 employes buys a server for 30k he will work illigal (so are back to my beginning post)
    The Question is if indesign is really needed. today i see many prints going out by pdf... so there could be easier ways
    take a look on some report generators like crystal reports. for many needs absoloutly enough

  • How to run apps in background

    I wish to run an application in the background so that it does not show up in (and take up valuable space on) the dock. How do I do this? I've tried setting the "Hide" check box in the account preferences but the app still shows up in the dock.

    what you can do is click the home key 2 and see if the app is open if not just open it and then lock the ipod

  • How to run oli7bw in background??

    Hi all
    I would like to run the oli7bw transaction in background .
    how to do it?
    thanks in advance,
    Jayashree

    Hi,
    Put the selections in, enter a name for the run, enter a setup date and time for the future.  Click on menu option Program --> execute in background.  It will popup print parameter select the ok button> it will give another pop-up for start time.  You can select immediate and the job will be scheduled immediately in the background, or you can select Date/time and give a date & time it should start.
    Cheers..
    PS: I hope you are in the testing phase and not doing it in the live environment.

  • How to run RPUBEN62 in background

    We designed our savings plan as an automatic plan and the business process is to have HR run HRBEN0012 to enroll hires every Monday morning.  However, our HR do not want to run this manual process.
    We tried to put RPUBEN62 on background job, but failed because it performs the 'Call screen 2000.' command in the END-OFSELECTION event in include BEN62E01, and this command causes the program to stop processing and the SAP GUI window is closed.
    We contacted SAP support and was told that RPUBEN62 is designed to run foreground, and we just started contacting SAP to see whether we can convince them to offer background run option.
    Any suggestion?  We do not want to clone the program if possible.
    Thanks.

    Sorry was searching for something else and seen this post, kinda old.
    We created a custom copy of   RPUBEN62, and run on a daily basis in the background. It is possible and saves some work for HR by automatically creating the standard plans for all new employees.
    B~

  • How to run LSMW  in Background

    Hi friends,
       I need some information. Is it possible to run an LSMW in Background. If so which type of programs we can run in Background which types are not?
    Regards,
    Naren.

    hello all,
    Regarding Session method :
    in  Run Batch Input session, we can use foreground or background.
    Direct input:
    Create Material with transaction „BMV0“
    Go to transaction SE38, choose the program “RMDATIND” and create a variant (direct relation to the run; Exp. Creation of the MRP view. Choose the appropriate entries in the following screen and save the variant.
    Click in the BMV0 on this button   then you get to this screen. Create a entry with you “Variant name” and save it.
    Important: Check in the P-System if you can create a entry in this table!!
    After the definition, choose the button  .
    Check the Job with TA: SM37
    This screen appears if you start the MBV0 from the LSMW
    Just press F8 to continue. You will get to this screen.
    This transaction gives you a Job log, protocol and also the possibility to restart a job in case of errors.
    reg,
    P_sonar

  • How to run apps in background in IOS5 ?

    hi,
    i use textfree as my ipod touch as my phone. when i get an incoming call, the textfree takes a long time to launch n hence i'm missing the calls. is it possible to run the textfree in background all the time, so the app dont have to launch when i get an incoming call by notification.
    thx

    what you can do is click the home key 2 and see if the app is open if not just open it and then lock the ipod

Maybe you are looking for

  • User unable to delete calendar event "unknown error"

    User is running Outlook 2013 home business, and she has a calendar entry that is linked to another mailbox . When I browse this mailbox from OWA or Outlook client i cannot see this calendar entry.  When the user tried to delete the entry, they receiv

  • On bank web site opening a check shows in a new window and cannot access the print capability in Firefox

    When I open a check picture from my bank register it opens in a new window and I cannot print from that window. I want to be able to print to the pdf printer so that I can save a copy of my check to the hard drive. I do not have any access to any pri

  • Adobe Reader Pro -

    Hello, I have signed into our trial account of the Adobe Reader Pro- I have selected a PDF Document to Convert to Excel.... Once I click on CONVERT I get the message An Error Occurred while signing in.... However I have signed in ok and been able to

  • Ghost contact group after syncing with Exchange?

    There seems to be bugs in syncing iPhone with Exchange. After I connected to an Exchange 2007 account, I have the following groups on the iPhone: - All contacts - (EmployessList) - Contacts - WORK - PERSONAL - TEMP I do have WORK, PERSONAL, and TEMP

  • Document.getElementById().innerHTML Not Working in Dreamweaver

    Hello! I have Dreamweaver CS5, and am trying to get JavaScript to work in it. I'm using the example from this online tutorial, which is for an imagemap: http://www.w3schools.com/js/js_image_maps.asp Click here to see the working code: http://www.w3sc