Suspend and Resume a certain thread

The question is quite simple.
How do I suspend a thread, and then wake him up from another thread?
I can't use wait and notify, because the idea is to have a list of suspended thread, and wake up
only one of them from another running thread, using a certain policy.
The idea would be to do something like
Thread 1,2,3,4 etc...
1.Save thread id, or thread object in the list
2. Suspend the thread
Thread N
1.Pick up a thread to wake up using a certain policy
2.Pop out the thread from the list
3.wake him up.
How do I do that in Java? If possible..
Thanks,
Salvo

Basically the new object created is placed into a list, and then
from another method, I call notify on one of the object stored in the list,
so what I expect is to wake up the thread who initially call the wait on the very
same object.
By adding making display the stack track into the exception handler, I realized
that the wait actually fails with the following.
java.lang.IllegalMonitorStateException
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:485)
        at SemaphoreFifo.Down(SemaphoreFifo.java:58)
        at Cliente.run(Cliente.java:29)I looked up for this exception and found
Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor.
By owning, does it mean it has to be a member of the thread class?

Similar Messages

  • Java Thread suspend and resume problem

    Hi,
    I am trying to write a program to implement thread suspend and resume using wait() and notify without using the deprecated methods like resume and suspend.
    I have written the following program which compiles but when I run it hangs without terminating. There seems to be some logic error but I am not able to catch it.
    Please help
    public class TestSuspendResume {
      public static void main(String[] args) {
        MyThread m1= new MyThread("--One-- ");
        MyThread m2= new MyThread("--Two-- ");
        m1.suspendMe();
        try {
          Thread.sleep(1500);
          m1.t.join();
          m2.t.join();
        } catch(InterruptedException e) {
          e.printStackTrace();
        m1.resumeMe();
        System.out.println("Now : end main thread");
    class MyThread implements Runnable {
      boolean suspend = false;
      Thread t;
      MyThread(String name) {
        t = new Thread(this,name);
        t.start();
      void resumeMe() {
        suspend = false;
        notify();
      void suspendMe() {
        suspend = true;
      public void run() {
        try {
          for(int i=0;i<20;i++) {
            System.out.println("Now : "+Thread.currentThread().getName()+i);
            Thread.sleep(200);
            synchronized(this) {
              while(suspend)
                wait();
        } catch(InterruptedException e) {
          e.printStackTrace();
    }

    Thanks for that response. I figured out that was the problem in the logic. I have modified the code to make it simpler but it is still hanging.
    public class TestSuspendResume {
      public static void main(String[] args) {
        MyThread m1= new MyThread("--One-- ");
        try {
          m1.suspendMe();
          Thread.sleep(1000);
        } catch(InterruptedException e) {
          e.printStackTrace();
        try {
          m1.resumeMe();
        } catch(Exception e) {
          System.out.println("ASASAS");
          e.printStackTrace();
        try {
          m1.t.join();
        } catch(InterruptedException e) {
          System.out.println("WOWOW");
          e.printStackTrace();
        System.out.println("Now : end main thread");
    class MyThread implements Runnable {
      boolean suspend = false;
      Thread t;
      MyThread(String name) {
        t = new Thread(this,name);
        t.start();
      void resumeMe() {
        if(suspend==true) {
          suspend = false;
          notify();
      void suspendMe() {
        suspend = true;
      public void run() {
        try {
          for(int i=0;i<20;i++) {
            System.out.println("Now : "+Thread.currentThread().getName()+i);
            Thread.sleep(200);
            synchronized(this) {
              while(suspend)
                wait();
        } catch(InterruptedException e) {
          System.out.println("-- E In run method -- "+e.getMessage());
    }

  • Thread: suspend() and resume()

    Hi,
    Both suspend() and resume() methods are deprecated, but I've used it anyway. I've realised my code can get into a deadlock.
    Is there anything I could use other than suspend and resume, but providing the same functionality?
    Many Thanks

    You should use wait and notify. There is a good
    discussion of this at the bottom of the deprecation
    notes on stop, suspend and resume.Yes, I just saw that. Before, I was looking at an old API.

  • Halt/Reboot fails if triggered after Suspend and Resume

    I'm using arch linux with gnome-shell and pm-utils. Halt/Reboot works alright normally, but when the sytem suspends and resumes, and then is halted/rebooted, the same fails.
    The screen shows an indication (message on console) that it's halting/rebooting, but it gets stuck there. There aren't any indication of failures/errors.
    Is there someone else facing the same problem? The cause? I'll be happy to give any relavant information required for this matter, in the form of system information or any logs,
    but at this point i'm not sure what would be relavant.

    Sorry this seems to be an existing issue in the forum: https://bbs.archlinux.org/viewtopic.php?id=113985
    Will update if any of the suggestion in the above mentioned thread fixes the problem.

  • Bit locker encryption requests key unless I suspend and resume the encryption

    I am rolling out new computers with Windows 7 Enterprise OS on them.  I am installing bit locker encryption on them.  For some reason with this group of computers, and I recently rolled out a different batch of computers without this problem,
    after encrypting, I must suspend and resume bit locker or upon restart of shutdown and start the user is prompted for the bit locker encryption key.

    Hi,
    Could you please tell some more details about the issue? What do you want to achieve here? To enable bitlocker without the prompt of the startup key? If it is , then please take a check if we have  Require
    additional authentication at startup  policy enabled.
    Besides, could you please have a share for how do you enable bitlocker?
    And here is a guide for bitlocker in Windows 7, just for reference:
    BitLocker Drive Encryption Step-by-Step Guide for Windows 7
    BitLocker Drive Encryption in Windows 7: Frequently Asked Questions
    Hope this may help
    Best regards
    Michael Shao
    TechNet Community Support

  • Suspend and resume of WD ABAP applicaiton support in the Portal

    Hello,
    I am implementing Suspend and resume feature in WD ABAP. It works fine in NWBC and also in stand alone. But in the portal it does not seem to work. I have done the following.
    1. Created a resume pulg (The applicaiton is suspended as I can see the state to suspend in the WDDOSTATECHANGED method.
    2. The navigation in the portal is in place and WD applicaiton is replaced by my target BSP
    3. I am NOT firing any plugs so there is no problem here
    Now what is not happening is the following.
    1. The sap-wd-resumeurl is not part of the url parameters so I am not sure when the WD applicaiton is suspended this parameter is really sent or not?
    2. Since I do not have the resume URL when I press the back in the portal window (right hand side top of the page) the resume plug is getting fired. But the parameters that I have set in the BSP are not part of the url parameters in the resume plug
    3. If I explicitly pass the sap-wd-resumeurl as a url paramter to the BSP (hard code the resume URL since I know the PCD path of my WD iview) and then use this URL to naivagate from the BSP then the WD applicaiton is started but the resume plug is not fired. In SM04 I can see a new session created now.
    4. Step 4 works fine (the suspend and resume) works fine when I repeat it the second time.
    A quick help will be really appriciated. I am on SP14 of NW 7.0
    Thanks and best regards,
    Harish.

    Hello,
    I am implementing Suspend and resume feature in WD ABAP. It works fine in NWBC and also in stand alone. But in the portal it does not seem to work. I have done the following.
    1. Created a resume pulg (The applicaiton is suspended as I can see the state to suspend in the WDDOSTATECHANGED method.
    2. The navigation in the portal is in place and WD applicaiton is replaced by my target BSP
    3. I am NOT firing any plugs so there is no problem here
    Now what is not happening is the following.
    1. The sap-wd-resumeurl is not part of the url parameters so I am not sure when the WD applicaiton is suspended this parameter is really sent or not?
    2. Since I do not have the resume URL when I press the back in the portal window (right hand side top of the page) the resume plug is getting fired. But the parameters that I have set in the BSP are not part of the url parameters in the resume plug
    3. If I explicitly pass the sap-wd-resumeurl as a url paramter to the BSP (hard code the resume URL since I know the PCD path of my WD iview) and then use this URL to naivagate from the BSP then the WD applicaiton is started but the resume plug is not fired. In SM04 I can see a new session created now.
    4. Step 4 works fine (the suspend and resume) works fine when I repeat it the second time.
    A quick help will be really appriciated. I am on SP14 of NW 7.0
    Thanks and best regards,
    Harish.

  • Suspend and resume

    hi
    can anybody tell me why suspend and resume methods have been deprecated in java 1.5. Can you explain with an exmaple
    thanks

    They were deprecated long before that. If you read their docs, there's a link that explains why.

  • Suspend and resume hook help

    I'm writting a hook for suspend/resume, however I've run into some trouble.
    So basicly what I need is:
    a) A script to stop and start mpd [done] (That's easy. Just setup mpd.conf's RUNAS user to the desired username and regardless that the mpd command is run as root it will run as the desired user)
    b) A script to stop and start oss4 since it fucks up after suspend [DONE] (piece of cake...)
    c) A script to view my wlan0 essid, save it to file, killall dhcpcd (the dhcpcd part, at least, is easy) and on resume to enter it again and run dhcpcd. [Need help]
    (In order to start my wifi I use iwlist wlan0 scanning, I choose the desired network and then iwconfig wlan0 essid DESIREDESSID and dhcpcd wlan0, but after suspend wlan0 looses it's settings so I need to make a script to enter them back.)
    I was thinking about something like iwconfig wlan0 | grep ESSID, but it returns (as expected)
    [dheart@lightbringer ~]$ iwconfig wlan0 | grep ESSID
    wlan0 IEEE 802.11g ESSID:"ESSID_NAME"
    I'm quite new at bash scripting and I have no idea how to write something that complex.
    d) Also sonata, my desired mpd frontend looses connection to mpd if mpd is restarted while it is running. So I need something to stop sonata (that's easy - killall sonata) and after that to run it (but not as root)... So, my question is how to run a program as normal user from  /etc/pm/sleep.d/ hook [NEEDHELP].
    Here's what I've written so far
    #!/bin/bash
    case $1 in
    hibernate)
    echo "Killing mpd and stopping oss4"
    mpd --kill & /etc/rc.d/oss-linux-free stop
    suspend)
    echo "Killing mpd and stopping oss4"
    mpd --kill & /etc/rc.d/oss-linux-free stop
    thaw)
    echo "Starting oss4 and mpd"
    /etc/rc.d/oss-linux-free start & mpd
    resume)
    echo "Starting oss4 and mpd"
    /etc/rc.d/oss-linux-free start & mpd
    *) echo "Wrong call"

    you're probably better off starting network autodetection on resume, I know most people suspend to go between, for example, home and work, or home and the intarwebz cafe, and seldom suspend and resume in the same location reliably.

  • Suspend and resume only works with fallback image

    I get a black screen on suspend and resume with pm-utils after I boot with main kernel image.
    However, fallback image works fine.
    I'd like to figure out what's missing in the main kernel image.
    lsmod looks the same with both images.
    How should I proceed?

    you are my hero...before I read this post I could never resume my laptop running Arch no matter what quirks I tried. That's actually why I've been running Fedora - resume worked. In fact, resume works on every other distro I've tried.
    As far as an ACPI update being to blame, I've had problems resuming in Arch for over a year, although I can't go back in time to try the fallback and see if it works
    When I get some spare time, I'll copy the mkinitcpio config for fallback to the main config and start removing modules / hooks to see which one breaks it
    EDIT: /etc/mkinitcpio.d/kernel26.fallback no longer exists - it just uses autodetect. Also, the loaded modules are the same no matter which image was used to boot, so I'm stumped. Maybe somebody who knows more about that mkinitcpio does can shed some light
    Last edited by wizzard (2009-03-07 16:43:10)

  • Suspend and Resume Plug

    Hi all,
    Here: <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/68/3aee42c4257176e10000000a1550b0/frameset.htm">http://help.sap.com/saphelp_nw2004s/helpdata/en/68/3aee42c4257176e10000000a1550b0/frameset.htm</a>
    is written about Suspend and Resume Plugs, and how to use them.
    I have one question about it:
    "<b><i>To be able to put a Web Dynpro application into the suspend state and resume it later on, you must set the Suspensibility (sap.suspendable.application) application property to true.</i></b>"
    Is this <b>SelfDefined</b> property for the webdynpro application? if- no, what have to be done, so to be set?
    Thank you in advance.
    BR

    Hi Diana,
    the only way to define a Web Dynpro application explicitly as suspendable is to define a specific application property named sap.suspendable.application. Possible values are true or false. Not defining this parameter means that the application is not suspendable.
    Check the document <a href="https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/102ed591-62a6-2910-94ac-e6038ef7b76e">How to realize suspendable Web Dynpro Java applications within the SAP NetWeaver Portal</a>. There you will find detailed instrcutions how to set the property.
    Best regards,
    Martin

  • SOLVE strange problem with suspend and resume with gnome-power-manager

    I have pm-utils and gnome installed.
    Suspending and hibernation works well from the command line ($ pm-hibernate and $ pm-suspend).  Resuming works without any problems.
    Suspending from gnome "Shutdown dialog" works perfectly as well.
    However, if suspending is initiated by gnome-power-manager something strange happens:  After pressing the power button resuming switches to hibernation and my laptop turns off.  Resuming from disk works fine again.
    Now, suspending works fine again if I change and save any config file in /etc/pm/.
    Here comes the strange thing:  It doesn't really matter what I change as long as I save it.
    However, as soon as I reboot resuming fails again the way I described above.
    Anyone have a clue what's going on?
    I get no error messages and I've tried all sorts of boot entries.
    Last edited by mehldutt (2007-12-26 19:42:31)

    After some try and error my guess is that "HAL" is responsible for this problem:
    I deinstalled ACPID and 'pm-utils' and switched to 'uswsusp'.
    I made the appropriate changes to the appropriate hal-scrips
    usr/lib/hal/scripts/hal-system-power-suspend:
    #!/bin/sh
    /sbin/s2ram --force
    usr/lib/hal/scripts/hal-system-power-hibernate:
    #!/bin/sh
    /sbin/s2disk
    After these changes I still have the same problem:  immidiatly after resuming form suspend (via power-button) my laptop hibernates (s2disk).
    However, if I delete all entries in "usr/lib/hal/scripts/hal-system-power-hibernate" resuming from suspend works fine again, but hibernate doesn't of course.  So, some script must be calling "usr/lib/hal/scripts/hal-system-power-hibernate" emmediatly after resuming from suspend.
    A couple of weeks ago everything worked fine.  My guess is that one of the recent hal-updates is causing this.
    How can I figure what script is calling "usr/lib/hal/scripts/hal-system-power-hibernate" after resuming from suspend?

  • Suspending  and resuming a running job in oracle

    Hi All,
    We can suspend the running job in oracle I believe so using DBMS_SCHEDULER.Can you please let me share your experience on this
    SQL> select owner,job_name,state from dba_scheduler_jobs;
    OWNER JOB_NAME STATE
    SYS TEST_STATS RUNNING
    SYS TEST_FULL_JOB_DEFINITION SCHEDULED
    SYS XMLDB_NFS_CLEANUP_JOB DISABLED
    I want to suspend the above job which is running and later want to resume.
    Best regards,
    Rafi

    dbms_scheduler is a documented package. As stated in the Forums Etiquette post, kindly consult the documentation first. Only when the documentation is unclear, ask for clarification.
    Sybrand Bakker
    Senior Oracle DBA

  • No Audio On Win7 x64 or Linux until I suspend and resume (then it works)

    Okay...this problem is *very* strange.
    Basically, I bought this laptop, an L665D-S5076, all works fine so far. Except for sound.
    Right when I opened it up, I booted into windows and updated the BIOS, everything was working fine (not sound)...
    I rebooted to verify that the BIOS update worked (I updated because I saw before I purchased it..of the of interest changes that were made to it).
    I then wanted to install Linux (specifically ArchLinux), being that I only use Windows for gaming. For everything else, Linux is much better at it.
    I wiped the entire hard disk (the whole partition table), installed Windows 7 x64 bit from a disk I had lying around...Note that I removed the recovery partition, and all of the other junk partitions which took up more space than I had wanted (and the MS-DOS Master File Table only supports up to 4 primary partitions...and of course, Windows consumes nearly all of them.).
    So I installed Windows 7...installed Linux...all of it was clean, I installed drivers for Windows...and even in Linux, everything works properly(surprised - apparently the majority of the chipset seems to be very open-source/linux friendly..which is great).
    Anyways, I just happened to close my screen and forgot that Windows 7 defaults to sleeping when that is done. So I resumed it and suddenly heard my sound working...
    So I rebooted and the sound didn't work...but suspending to RAM and then resuming fixes it...
    The _strangest_ thing, is that not only does it do this in Windows, but it does it in Linux too. The Exact..same..issue..
    Didn't expect that...
    So basically now I want to get sound working without needing to suspend to "fix" it. Obviously ;-)
    And please don't even think about saying "remove that strange thing that you called Linux" just because it "isn't recommended" or something...especially since Linux cannot physically *touch* Windows, in the state I have it in.
    Thanks, I'd really love to listen to music in Linux & play games w/ sound in Win7 ;-)
    Also, was it 64-bit that this machine shipped with? I didn't pay attention to it/care. Just curious..although the drivers say they support both which is nice. I assume it did, since it can't allocate >3 gigs in the x86 arch.

    Called tech support and was told to ship it back to toshiba - appears to be a hardware issue. Would explain why the issue is present in both windows & linux. If their repair processing is as good as their support seemed, then it should all go smoothly....Hopefully it will get processed quickly and I will not have any future hardware issues - I really need to use this for school...But I guess that is with anything, when you get a dud you immediately think that all of them are going to be like that.

  • Suspend and Resume Presentation

    I would like to be able to execute (probably by URL or Java
    script) an WebStart application which would need to execute along
    with the captivate session (which would be simulating a application
    Navigation).
    Once the external application completes is there a way to
    invoke a method to make captivate move to the next step?

    Welcome to our community, Coconut42
    While there is no easy way I can think of that will make an
    application such as WebStart, I'm guessing the answer to this would
    be as simple as inserting a Click Box or Button object on a slide
    in Captivate.
    Here's the deal. Both of these object types cause the slide
    to pause dead in its tracks until your user interacts by clicking
    or otherwise (shortcut key). So I'm guessing you are using either a
    Click Box or Button object on say, Slide 12 to launch the WebStart
    application. This would cause the Captivate project to continue
    playing unless you configured it otherwise. So what I'm suggesting
    is that you would insert a Click Box or Button object on say, Slide
    13 that would pause Captivate at that next slide. This should give
    the illusion that your WebStart is talking to Captivate.
    User is on Slide 12 and clicks to launch WebStart. Slide
    advances to 13 and pauses (while the Captivate movie is behind the
    WebStart application) and when the user closes WebStart, there's
    the Captivate project presenting Slide 13 and patiently waiting for
    the user.
    Would this do what you need or did I misunderstand?
    Cheers... Rick

  • System loses ability to suspend after resume

    After the last time I updated, I noticed some issues with suspend and resume on my laptop. Because of these problems, I haven't updated my desktop as of yet until I understand what is going on.
    I frequently suspend and resume my laptop as I move from class to class during the day. In some places (such as the library), I have my computer plugged in. In others (such as during lecture), I use battery power. I noticed that if I suspend while on ac power and resume on battery (or vice versa), the system loses contact with dbus and can't suspend, poweroff, or reboot. If I try to suspend by closing the lid, it says "Operation already in progress". If I try to suspend, poweroff, or reboot using systemctl or the menu buttons, it says that it can't contact dbus. My only option is to hold down the power button until the computer turns off and reset the whole system. This is coming from a relatively stable system that, before this slew of updates, stay on for 15+ days without a restart if I didn't run updates or have any issues with hardware.
    Another symptom that may be relevant is that when I resume during one of these hiccups, it kicks me from tty7 (gui) to tty1 when the computer wakes up and I have to switch back to tty7. I am using xfce + SLiM as my desktop environment.
    My log says this during one of these suspend-resume hiccups:
    Sep 26 00:15:17 kcuzner-netbook systemd[1]: Starting Sleep.
    Sep 26 00:15:17 kcuzner-netbook systemd[1]: Reached target Sleep.
    Sep 26 00:15:17 kcuzner-netbook systemd[1]: Starting Suspend...
    Sep 26 00:15:17 kcuzner-netbook systemd-sleep[2424]: Suspending system...
    Sep 26 08:02:31 kcuzner-netbook kernel: PM: Syncing filesystems ... done.
    Sep 26 08:02:31 kcuzner-netbook kernel: PM: Preparing system for mem sleep
    Sep 26 08:02:31 kcuzner-netbook kernel: Freezing user space processes ... (elapsed 0.232 secon...ne.
    Sep 26 08:02:31 kcuzner-netbook kernel: Freezing remaining freezable tasks ... (elapsed 0.001 ...ne.
    Sep 26 08:02:31 kcuzner-netbook kernel: PM: Entering mem sleep
    Sep 26 08:02:31 kcuzner-netbook kernel: Suspending console(s) (use no_console_suspend to debug)
    Sep 26 08:02:31 kcuzner-netbook kernel: wlan0: deauthenticating from ee:43:f6:36:9a:54 by loca...=3)
    Sep 26 08:02:31 kcuzner-netbook systemd[1168]: Time has been changed
    Sep 26 08:02:31 kcuzner-netbook systemd[1]: Caught <SEGV>, core dump failed.
    Sep 26 08:02:31 kcuzner-netbook systemd[1]: Freezing execution.
    Sep 26 08:02:31 kcuzner-netbook systemd-sleep[2424]: System resumed.
    Sep 26 08:02:32 kcuzner-netbook systemd-cgroups-agent[2500]: Failed to get D-Bus connection: Fai...d
    Sep 26 08:02:31 kcuzner-netbook dhcpcd[1362]: wlan0: carrier lost
    Clearly the <segv> is the issue here, but I don't know how to access any data about that or diagnose it. Has anyone had a similar issue or know how I can go about solving this one?
    Last edited by Los Frijoles (2013-09-26 14:27:30)

    https://bugs.archlinux.org/task/37027

Maybe you are looking for

  • Clean install with least amount of disk space?

    Hi, I just ordered a MBP 15", with a 128gb SSD. When it arrives, I'd like to do a re-install and select only the options/languages that are necessary for me. Is there a tutorial, or can you help me with some tips on making the footprint as small as p

  • Workbook Variants lost on change of query

    All, We have found that we lose our workbook variants when we modify the underlying query. Does anyone know whether these can be recovered. Regards Nev

  • How to make available the peoplesoft PIA over the internet

    Hi All, I have installed PT 8.52 and HCM 9.1 in my local.. But during my free time in office I want to learn functional HCM modules so I just want to make the PIA link available over the internet so that I can access from anywhere. Please guide me ho

  • SharePoint 2013 SSRS integration Report keep refreshing while display in ipad

    I had deploy the ssrs report in SharePoint Integration mode, but report keep refreshing by pop up the loading animation and cannot display the report eventually. It only happens in ipad 2/3 and iphone 4(ios 7), but the report can be display completel

  • Application Manager check for updates

    How can I add AIR, Flash Player and Reader to the list of applications that Elements 10 Application Manager checks for updates?