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).

Similar Messages

  • 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 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();
    }}

  • Is it possible to create a thread and run it in background in nokia ??

    Is it possible to create a thread and run it in background in nokia series 40 mobile phones using j2me ??

    Probably a good question for ForumNokia. If you mean start up a thread and run in the background while your MIDlet UI does other things, then sure, why not. If you mean that you want to exit your MIDlet, but leave a thread running in the background, then I don't believe you can do this on series 40. S60 is another story since it supports multiple tasks.

  • Camera shows a black preview, if there is any operation running in the background thread.

    Hi,
    Camera launched from app using UIImagePickerViewController shows a black preview, if there is any operation running in the background thread. This was not an issue in ios 6. Can you please fix this with next update?
    Thanks & Regards,
    Dileep Kumar

    Some things that might help:
    1. Only the most recently used apps actually occupy memory (used to be the most recent 4, but may have changed in the latest iPhones). After 4 (or so), IOS writes them out of active memory, as it does for even the latest 4 if there's no activity for a long time. So the business of closing all the open apps, apart from the most recent ones doesn't make a difference. Tis article has a good explanation:
    http://www.speirs.org/blog/2012/1/2/misconceptions-about-ios-multitasking.html
    2. There are settings about background app activity that might help:
    - Settings, General, Background App Refresh controls which apps can update their data in the background
    - Settings, Notifications controls which apps can tell you things, which they have to wake up to do.
    - Settings, Privacy, Location Services controls which apps monitor your location - another activity that uses resources
    Hope some of that helps

  • The application does not use the  screen and run in the background

    Hi
    I have downloaded a package of j2me Midlet
    from [link] here [link]
    and try to reuse the code
    but I get the following error when running the code:-
    The application does not use the screen and run in the background
    I think the error into one of these two classes
    package main;
    import javax.microedition.midlet.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import java.io.IOException;
    import java.io.InputStream;
    public class MainMidlet extends MIDlet implements CommandListener {
        private SSGameCanvas gameCanvas ;
        private Command exitCommand ;
        private Player player = null;
        public void startApp() {
      try {
           //   create new game thread
              gameCanvas = new SSGameCanvas();
              gameCanvas.start(); // start game thread
              exitCommand = new Command("Exit",Command.EXIT,1);
              gameCanvas.addCommand(exitCommand);
              gameCanvas.setCommandListener(this);
                Display.getDisplay(this).setCurrent(gameCanvas);
       catch (java.io.IOException e)
                e.printStackTrace();
            try {
                // start sounds
                InputStream in = getClass().getResourceAsStream("/resource/startfly.wav");
                player = Manager.createPlayer(in,"audio/x-wav");
                player.setLoopCount(1);
                player.start();
            catch (MediaException ex)
                ex.printStackTrace();
             catch (IOException ex)
                ex.printStackTrace();
        public void pauseApp() {
        public void destroyApp(boolean unconditional) {
            if (player != null) {
                player.close();
            System.gc();
      public void commandAction(Command command, Displayable displayable) {
           if (command == exitCommand)
                 destroyApp(true);
                 notifyDestroyed();
    package main;
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class SSGameCanvas extends GameCanvas implements Runnable {
        protected GameManager gameManager;
        protected boolean running;
        private int tick=0;
        private static int WIDTH;
        private static int HEIGHT;
        private int mDelay = 20;
        Form mainForm;
        Display display;
        //private int MaxTime;
        public SSGameCanvas() throws IOException{
            super(true);
            gameManager = new GameManager(5,5,getHeight()-10,getWidth()-10,this);
        public void start() {
                this.running = true;
                Thread t = new Thread(this);
                t.start();
        public void stop() {
            running = false;
        public void render(Graphics g) {
            WIDTH = getWidth();
            HEIGHT = getHeight();
            // Clear the Canvas.
            g.setColor(0, 0, 50);
            g.fillRect(0,0,WIDTH-1,HEIGHT-1);
            // draw border
            g.setColor(200,0,0);
            g.drawRect(0,0,WIDTH-1,HEIGHT-1);
            // draw game canvas
            gameManager.paint(g);
        public void run() {
            while (running) {
                // draw graphics
                render(getGraphics());
                // advance to next graphics
                advance(tick++);
                // display
                flushGraphics();
                try { Thread.sleep(mDelay); }
                catch (InterruptedException ie) {}
        public void advance(int ticks) {
            // advance to next game canvas
            gameManager.advance(ticks);
            this.paint(getGraphics());
    }Edited by: VANPERSIE on Jul 10, 2012 12:26 PM

    Hi Andi,
    Thanks for your reply.
    Yes, I have waited for a while and the result doesn't change.
    The Porblem here is the application is seen started in visual administrator.Only restart brings up the page back.
    Can you please suggest anything.
    Thanks and regards
    Nagaraj

  • Applications running in the background

    Does anyone know if there is a way to see which appplications are running in the background?  My battery keeps discharging at a faster rate than normal and I assume I have left an application running (without menu-close) and that it is causing the battery drain.
    Thanks

    Press ALT + Escape (the key to the right of the trackball) to view the background apps.
    Read here, #2 tip under "Tips for reducing fast battery drain":
    Here are some good charging tips, please read and you'll see that many of them will apply to you.
    http://www.blackberrynews.com/2008/05/20/battery-use-tips-for-your-maximum-battery-life/
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • 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

  • Are Apps Running In The Background All The Time?

    are apps always running in the background or is just double pressing the home button just a fast way to switch to what u were doing like texting or phone or something?
    cause ill notice i lot of icons down there lol and i hope not all those are running in the background cause i could see that killing the **** outa my battery -_-

    ... and here's an excellent thread explaining all the details:
    http://discussions.apple.com/thread.jspa?threadID=2479111&tstart=120

  • Is there anyway to close apps running in the background with the new IOS 7 operating system?

    I would like to be able to close apps running in the background and haven't figured out if I can do it  or how to do it with the new operating system update. I would appreciate any help. Thanks and have a good day.

    Just look at this thread - https://discussions.apple.com/thread/5363937

  • Running function in background - even while previous call to this function is running

    Hi everyone. I have a WPF C# .Net 4.5.2 app, which receives GPS data from tracking devices out in the field via TCP and plots them on a map (using the WPF Bing Maps control). One of the things I do when receiving data from a tracker is to get the street
    address at the tracker's coordinates by using Bing's reverse geocoding facility. This can take a few seconds, and because I don't want it to slow down everything, I want to run this function in the background (i.e. in a separate thread). So I thought about
    using .Net 4.5's Async/Await feature. This is how it looks:
    private async void GetStreetAddress(int trackerId, double lat, double lng)
    string streetAddress = await bingMap.ReverseGeocodeAsync(lat, lng);
    dal.UpdateTracerAddress(trackerId, streetAddress);
    So basically it calls Bing Map's reverse geocoding function, gets a street address, and updates this tracker's address in the database (MySQL database). Just to complete the picture, the ReverseGeocodeAsync shell looks like this:
    public async Task<string> ReverseGeocodeAsync(double lat, double lng)
    string streetAddress = "";
    //Reverse Geocoding code...
    return streetAddress;
    My question is the following: What happens if the GetAddress() function is called again while it is still running? So, normally the app receives TCP data from one of the trackers, and then calls the GetAddress() function to get the street address.
    Now, while that function is running in the background, the app receives another packet of TCP data and again calls that same GetAddress function before the previous instance has finished. Will it just create another instance of that function on the stack?
    Thanks
    Fabricio Rodriguez - Pretoria, South Africa

    If your code is definitely working as expected and is executing ReverseGeocodeAsync on a different thread then you can do that any number of times and they will all just run.
    It is quite easy to write async await and find the flippin thing runs synchronously though.
    I recommend you put a break point in that method
    public async Task<string> ReverseGeocodeAsync(double lat, double lng)
    string streetAddress = ""; // Break here
    Spin it up and give it a twirl.
    When you hit it that break point, open up the Threads window and make 100% certain what thread your break point is on.
    https://msdn.microsoft.com/en-us/library/w15yf86f.aspx
    I've seen code which looks like it'll run asynchronously just fine which turns out to be running synchronously.
    It's dead easy to go wrong.
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • How do I find out what applications are running in the background

    I have a 2008 iMac with 2GB memory.  How do I find out what programs are running in the background?  I am going to buy a new iMac before the end of the year to replace this one.  When I looked at Activity Monitor it shows 1.8Gb used but doesn't tell all the programs running.

    open activity monitor [if it doesnt launch click winders>Activity Monitor]. then it'll show all proceses

  • Adobe Bridge not running in the background

    I have bridge setup to load and run in the background when I start windows.  However it doesn't run in the background but launches and runs as normal.the icon does not load in the control panel as does other programs that load and run in the background. Running a 64bit windows 7 machine

    Ashutosh.Nigam wrote:
    If you want to  start Br at login, Follow below mentioned steps:
    In Bridge , choose Edit > Preferences (for Windows) or Adobe Bridge > Preferences (for Mac OS).
    Choose Advanced.
    Select Start Bridge At Login.
    You can disable this option at any time, Hope this helps.
    I don't have CC but others say the standard option is not there.  Can you confirm it is?

  • When I click on a new link, it opens a whole new firefox instead of using my default which is running in the background

    I have firefox as my default browser. Anytime I click on an email or search for something, instead of opening my default browser, firefox loads a new firefox page. It is a blank page just as if I had never had one. It has nothing on it except how you would start out before you set up your tabs and history etc. My default firefox is still there running in the background but I must click on it and manually put in the link I was trying to open.
    Any suggestions.

    Some added toolbar and anti-virus add-ons are known to cause
    Firefox issues. '''Disable All of them.'''
    Start '''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Firefox in Safe Mode]''' {web Link} by holding down the '''<Shift ''(Mac Options)'' >''' key, and then starting Firefox. Is the problem still there?

  • Long running threads (Jasper Reports) and AM-Pooling

    Hi,
    we are developing quite large application with ADF an BC. We have quite a lot of reports generated through Jasper that take quite long time to complete. The result is a PDF document that user gets on the UI so he can download it over download link. Reports that take over an hour to finish are never completed and returned to the user on UI. I think the problem is in AM-Polling because we are using default AM-Polling settings:
    <AM-Pooling jbo.ampool.maxinactiveage="600000" jbo.ampool.monitorsleepinterval="600000" jbo.ampool.timetolive="3600000"/>
    The AM is destroyed or returned to pool before reports finishes. How to properly configure those settings that even long running threads will do there jobs to the end.
    We also modified web.xml as follows:
      <session-config>
        <session-timeout>300</session-timeout>
      </session-config>
    Any help appreciated.
    Regards, Tadej

    Your problem is not related to ADF ApplicationModules. AMs are returned to the pool no earlier than the end of request, so for sure they are not destroyed by the framework while the report is running. The AM timeout settings you are referring to are applicable only to idle AMs in the pool but not to AMs that have been checked out and used by some active request.
    If you are using MS Internet Explorer, then most probably your problem is related to the IE's ReceiveTimeout setting, which defines a timeout for receiving a response from the server. I have had such problems with long running requests (involving DB processing running for more than 1 hour) and solved my problem by increasing this timeout. By default this timeout is as follows:
    IE4 - 5 minutes
    IE5, 6, 7, 8 - 60 minutes
    I cannot find what the default value is for IE9 and IE10, but some people claim it is only 10 seconds, although this information does not sound reasonable and reliable! Anyway, the real value is hardly greater than 60 minutes.
    You should increase the ReceiveTimeout registry value to an appropriate value (greater than the time necessary for your report to complete). Follow the instructions of MS Support here:
    Internet Explorer error &quot;connection timed out&quot; when server does not respond
    I have searched Internet for similar timeout settings for Google Chrome and Mozilla Firefox, but I have not found anything, so I instructed my customers (who execute long-running DB processing) to configure and use IE for these requests.
    Dimitar

Maybe you are looking for

  • Possible importing solution (works for me)

    Ok everyone, this worked for me. It's not perfect, but a lot better than 30 minutes a song! I found 2 things that worked. #1 "Minimize I tunes while you are importing" "Stretch your legs,go get another beer or whatever"When you come back, your cd wil

  • Line In Zen Nano P

    If this was posted somewhere before please just point me to the proper link, but, i'm a little hazy on the line in features of this device. If I connect one end to the Nano and one end to the headphone jack on a Sony walkman should I be able to recor

  • I have forgotten my answers of security question

    I have forgotten my answer for my security question, I tried to go on dicussion.apple.com look at all the question for this discussion/solutions I'm starting to get angry I just brought a 15 dollar gift card and now I can't use it

  • Standard Program

    Hi Experts , iam having a Tcode ME33K for Supplier Contracts .. Wat My Question  is : I need standard Report Program for ME33K Tcode .. Waiting for ur Reply Regs , Murthy

  • Ojdbc14.jar API and Oracle Database Version

    Hi Im using ojdbc14.jar for accessing an oracle 10G database. Im trying to troubleshoot an exception - java.sql.SQLException: Parameter Type Conflict that seems to get thrown by the method - OraclePreparedStatament.processCompletedBindRow I have a co