Threads waiting the same event

hi all,
i have two thread waiting an event
and another who notify them
//the class event
public final class Event {
* variable used to store the notification if it takes place
* before being expected
private boolean status = false;
public final synchronized void waitForNotification() {
while (status == false ) {
try {
wait();
catch (InterruptedException e) {
status = false ;
// notify all waits on this event
public final synchronized void wakeUp() {
status = true;
notifyAll();
// the class TestThread implements a thread that have an event waiting for a notification
public class TestThread extends Thread{
private Event event;
public TestThread( Event e){
event=e;
public void run(){
for (int i = 1; i < 4; i += 1) {
try {
Thread.sleep(2);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
e.waitForNotification();
// the class TestThread2 implements a thread that have an event waiting for a notification
public class TestThread2 extends Thread{
private Event event;
public TestThread( Event e){
event=e;
public void run(){
for (int i = 1; i < 4; i += 1) {
e.wakeUp();
//the class main
public class test {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
Event e = new event();
TestThread th1 = new TestThreadConsumer(e);
TestThread th2 = new TestThread(e);
TestThread2 th= new TestThread2(e);
th1.start();
th2.start();
th3.start();
1st case
the problem is that the notification could not be seen to the tow threads
because if the tow are waiting the notification
and the other thread send notification
one of the tow see the notificztion and wake up and set the flag status to false so the other one could not ever wake up
2d case
the notification of the second thread could be done in the second itiration or in the other ones
please could u answer and help me
thank you

nabila.abdessaied wrote:
i just wanna to have tow thread waiting a notification from another
and when another send the notification
they could go out from waiting and do their jobHi.
Below is an example of how you could do this. It is taken from http://www.javaconcurrencyinpractice.com/listings.html (5.11 Using CountDownLatch for starting and stopping threads in timing tests) .
The idea is simple:
(1) main thread starts nThreads, but all of them, once started, are "suspended" in startGate.await();
(2) when all threads are started, main thread calls startGate.countDown(); and all those waiting threads "are off" at once.
I'm not sure that you need 'endGate' though (but I thought that it is not that good to cut somebody's else example...)
* TestHarness
* <p/>
* Using CountDownLatch for starting and stopping threads in timing tests
* @author Brian Goetz and Tim Peierls
public class TestHarness {
    public long timeTasks(int nThreads, final Runnable task)
            throws InterruptedException {
        final CountDownLatch startGate = new CountDownLatch(1);
        final CountDownLatch endGate = new CountDownLatch(nThreads);
        for (int i = 0; i < nThreads; i++) {
            Thread t = new Thread() {
                public void run() {
                    try {
                        startGate.await();
                        try {
                            task.run();
                        } finally {
                            endGate.countDown();
                    } catch (InterruptedException ignored) {
            t.start();
        long start = System.nanoTime();
        startGate.countDown();
        endGate.await();
        long end = System.nanoTime();
        return end - start;
}Seems this is what you were looking for (if I understood you right).

Similar Messages

  • Threads waiting the same event :searching for a specific notificationfor

    hi all,
    i have two thread waiting an event
    and another who notify them
    //the class event
    public final class Event {
    * variable used to store the notification if it takes place
    * before being expected
    private boolean status = false;
    public final synchronized void waitForNotification() {
    while (status == false ) {
    try {
    wait();
    catch (InterruptedException e) {
    status = false ;
    // notify all waits on this event
    public final synchronized void wakeUp() {
    status = true;
    notifyAll();
    // the class TestThread implements a thread that have an event waiting for a notification
    public class TestThread extends Thread{
    private Event event;
    public TestThread( Event e){
    event=e;
    public void run(){
    for (int i = 1; i < 4; i += 1) {
    try {
    Thread.sleep(2);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    e.waitForNotification();
    // the class TestThread2 implements a thread that have an event waiting for a notification
    public class TestThread2 extends Thread{
    private Event event;
    public TestThread( Event e){
    event=e;
    public void run(){
    for (int i = 1; i < 4; i += 1) {
    e.wakeUp();
    //the class main
    public class test {
    * @param args
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Event e = new event();
    TestThread th1 = new TestThreadConsumer(e);
    TestThread th2 = new TestThread(e);
    TestThread2 th= new TestThread2(e);
    th1.start();
    th2.start();
    th3.start();
    1st case
    the problem is that the notification could not be seen to the tow threads
    because if the tow are waiting the notification
    and the other thread send notification
    one of the tow see the notificztion and wake up and set the flag status to false so the other one could not ever wake up
    2d case
    the notification of the second thread could be done in the second itiration or in the other ones
    please could u answer and help me
    thank you

    I'm locking this thread since it's a duplicate.
    The discussion will continue in: [http://forums.sun.com/thread.jspa?threadID=5377151&tstart=0]
    Kaj

  • ICal has dropped a monthly event for the previous four months....... why did it disappear? and where is it?  It was the same event but a different day each month.

    iCal has dropped a monthly event for the previous four months....... why did it disappear? and where is it?  It was the same event but a different day each month.

      I installed this same digitizer in my T|X some weeks ago.  Some discussion of my experience may be found in this Usenet posting and subsequent thread.
      The stock digitizer in my T|X had always had some significant alignment issues (for which PowerDigi was able to compensate very nicely) and sensitivity which was uneven, but which usually required a heavier touch than I liked.
      Eventually, it began to develop a “dead spot” near the upper left.  My T|X was under warranty, so I probably ought to have sent it in to Palm to be repaired, but I wasn't willing to be without it for the required amount of time, and I've heard enough reports of other T|X owners getting unsatisfactory results this way.  I'd heard enough good reports about the PDAPARTS.COm digitizer, that I decided that the only acceptable way to repair my T|X would be to install one of those.
      After however many weeks it has been, I am still very pleased with the results.  It continues to work flawlessly; it is much more sensitive, so it doesn't require nearly so heavy a touch, and I very much like the hard feel that it has, compared to the spongier feel of the stock digitizer.
      My wife's T|X still has its stock digitizer, and it has so far not shown any of the same problems that mine did, or for which the T|X has become notorious, but the feel is noticeably inferior.  She's content with it the way it is, but I think that if I were to ever buy another T|X for myself, I wouldn't wait for the stock digitizer to fail.  The PDAPARTS.COM digitizer is simply superior in every imaginable way; and, in my opinion, a T|X with the PDAPARTS.COM digitizer installed is sufficiently superior to one with the stock digitizer (even if it isn't defective) to be very much worth the expense and trouble of installing it.
    Post relates to: Palm TX

  • Can I have multiple event structures with the same event cases?

    Hello, 
    I'm doing an application that reproduces the front panel of the HP6675A power supply. To achieve this, I have done a state machine with different states
    (initialize, measures, voltage, current, ocp, ov, store, recall, etc). In each state, should have an event structure that catches the events of the buttons, like for example: if the current state is the Voltage mode and the user press the current button the next state will be the Current mode. For this in each state of the state machine should be the same event structure with the same events.
    My problem is that the Vi doesn't work properly when I have multiple event structures with the same event cases. There are some possibily to do this, and how? Or is impossible to have multiple events? I have been reading some posts, but I don't find solutions. 
    Any help is appreciated.
    Thank you very much.
    Solved!
    Go to Solution.

    natasftw wrote:
    Or as others mentioned, make two parallel loops.  In one loop, have your state machine.  In the other, have just the Event Handler.  Pass the events from the handler to the state machine by way of queues.
    A proper state machine will not need the second loop.  The "Wait For Event" or "Idle" state (whatever you want to call it) is all you really need in order to catch the user button presses.  The setup is almost there.  Maybe add a shift register to keep track of which state to go to in the case of a timeout on the Event Structure.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Communication between thread in the same process using file interface.

    Hi,
    I am developing  driver and i need to communicate between two thread.
    >can anyone guide me on implementing communication between two thread in the same process using File Interface. First thread will be driver and second will be application.I need to send IOCTL like commands using File interface ie is WriteFile(),ReadFile()
    from Host process to driver through file-interface(which run's in driver context).Host process should not be blocked for the duration of the driver to process the command.
    >File-interface will run in driver context and it will be responsible to receive command from application and pass it to the driver.
    what are the complexity introduced?
    >Can anyone also give me the link/reference to get more information on this topic?
    >How to replace IOCTL command's for instance baud _rate change command with a file interface for example with IRP.

    Here  is the detailed query:
    Hardware Abstraction Layer will interact with Driver(Both will be running in complete different process) .there is a IOCTL for command and  File interface for read and write.
    My requirement is:
    Both should run in the same process so HAL will run as one thread and driver as another thread in the same process .I don't want HAL to wait for completion of request and also i don't want driver to be blocked .
    We are planning to use a File Interface for communication between Hardware abstraction layer and Driver
    HAL will send the command or read/write operation to a file interface and driver will get the command or read/write request from the File interface
    There is a flexibility to change Hardware Abstraction layer and also the Driver
    Is it possible to use IOCTL between two thread under same process? if not what other options do we have.
    Can we use File interface to  send command (like IOCTL) between two thread?

  • Can multiple threads share the same cursor in berkeley db java edition?

    We use berkeley db to store our path computation results. We now have two threads which need to retrieve records from database. Specifically, the first thread accesses the database from the very beginning and read a certain number of records. Then, the second thread needs to access the database and read the rest records starting from the position where the cursor stops in the first thread. But, now, I cannot let these two threads share the same cursor. So, I have to open the database separately in two threads and use individual cursor for each thread. This means I have to in the second thread let the cursor skip the first certain number of records and then read the rest records. However, in this way, it is a waste of time letting the second thread skip a certain of records. It will be ideal for us that the second thread can start reading the record just from the place where the first thread stops. Actually, I have tried using transactional cursor and wanted to let the two threads share the same transactional cursor. But it seems that this didn't work.
    Can anyone give any suggestion? Thank you so much!
    sgao

    If your question is really about using the BDB Java Edition product please post to the JE forum:
    Berkeley DB Java Edition
    If your question is about using the Java API of the BDB (C-based) product, then this is the correct forum.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • FCPX 10.1.3 Project vanishes when a new project is created in the same event

    I've been working on avery complicated project all day with multiple layered clips with key frame animations, colour effects etc. All was fine until I opened a new project in the same event which I was going to use to create some effects sequences for the main project. When I went back to the original project it was empty. Tried the Undo function in case I had done anything stupid but it was greyed out. Went to the FCPX backups and the last file was almost 2 hours old but did not have any sign of this project. The only thing I have left is all the imported media.
    Any ideas? Using FCPX 10.1.3. This is really annoying as all I have left is an h264 file of the almost complete project and it will be almost impossible to start from scratch.
    Thanks for your attention

    The edited project was 60 seconds making up an intricate title sequence involving 24 video segments and 48 png/ PSD files.  Had a brain storm and was wondering if there is anyway the the project could move to another event so currently going through all the event folders on my FCPX edit drive. I just can't see how a project can just vanish.
    Thanks for your suggestion.

  • How can I use the same event case for different controls dynamically

    OS: Linux 2.6.24-1-686 #1 SMP Sat Apr 19 00:37:55 UTC 2008 i686 GNU/Linux
    LabVIEW: Version 8.2
    I have a lot of (about 50) controls (numeric, boolean) on my front panel. If a "Value Change" event will be fired by any of them the same event case shall be executed. As I do not want to add all 50 controls to the same event case manually I am looking for a way to do it at run time. Additionally the VI is still under contruction, i.e. controls will be added and removed.
    Thanks for any help here.
    Regards,
    Johannes
    Solved!
    Go to Solution.

    Hi Johannes,
    collect all your control references (you can use the FP property for it) and create a user event. Connect this user event to your event structure. Now you have one event case for all your controls. See the attached picture.
    Mike
    Attachments:
    Unbenannt1.PNG ‏11 KB

  • In FCPX, how do I use multiple clips of the same event?

    This is a beginner question, but having recently moved from Final Cut Express to FCPX, I am having trouble using 3 clips (church play, 3 cameras) of the same event (and reading through the manual has not helped me). I have lined them up in the timeline, one "on top" of the other, but the viewer only shows the top clip. I would like to see what the other clips look like and use the cutting tool and opacity (which I found) to choose the best view (and move between the clips lined up with the audio). It feels like I am trying to use an old work flow on a new product. How do I view the all the clips and move between them?

    Here is one of those free tutorials (in two parts), which , IMO, is particularly good.
    There is also, of course, more comprehensive paid training available that may better fit your needs.
    Good luck.
    Russ

  • I have photos from several cameras of the same event, how do I combine them?

    I have photos from several cameras of the same events.  How can I sort them together, three pics of the same horse from three cameras side by side; I can't move pics from one camera source to another in a folder.

    Languare is critical since it is all we have to communicate with
    Folders in iPhoto do not hold photos - folders hold only other folders or albums
    If you are speaking of events then you simply merge the events (drag one onto another or select two or more and use the merge events command - for the photos to be "side by side" the three camera's time/date setting will have to be identical as photos will be sorted by time/date - if they are not you can correct by selecting the photos in an event (before merging) and using the adjust time and date command or you can make a smart album for the camera and select the photos and use the adjust time and date command
    LN

  • Can I combine multiple threads from the same contact in iMessage?

    iMessage displays multiple threads for the same contact.  Its very confusing and has resulted in lost messages.  I've tried changing a number of settings but to no avail.  Seems to require everyone in my contact list to eliminate all their email addresses in iMessage.
    Begs the question why does iMessage even need this information?  Worse, why does it suck it into its settings by default.  The directory server should only require a valid Apple ID (associated with the users' devices)  in order to direct an iMessage between two contacts.

    Thanks for the reply, appreciate your input.  I did find another way of doing it and that is to highlight the first e-mail, hold down the shift key and click on the last one.  That highlights them all and then they can all be deleted.  Your ideas also work of course and I thank you for that.  Cheers.

  • How do I have the same "events" on two Macs?

    I have the "family pack" and just installed on both Macs. I have the same exact pictures on both Macs. I organized all the events on one Mac and now I would like to have the same events on the second Mac.
    On the previous version of iPhoto, I simply would copy com.apple.iPhoto.plist from the first Mac and copy it to the next Mac. Then all my preferences (e.g., file names, roll names, etc.) would match. This method does not seem to work on iPhoto 08.
    Any suggestions?

    John:
    You could use iPhoto Library Manager and copy the events from one library to another like this. The demo shows an event being copies but it works the same for albums.
    You'll need to connect the Macs so you have access to the libraries and then IPLM will do the job.
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've written an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • How to get rid of mutiple events showing in calenders for the same event

    How do you get rid of mutiple events that show up in your calender of the same event. It doesn't matter what kind of event it is whether personel or yearly holiday it shows up mutiple times in the month view, list view. I've gone through and deleted events manually and said for all future events but this is time consuming, because you have to do it for each event. Is there a qicker way of getting this done? Also just an off note I found out that my bluetooth headsets stop ringing throught the ear piece like they did before the upgrade, any insight into this?

    If I understand your question correctly...
    try the following
    from Sources, choose the greyed out streaming library that you want to be rid of...in your case, make sure it is the right one, since they both have the same name.
    You should get a screen that says "Library Unavailable" with 2 menu choices below that, "OK" and "Disconnect from iTunes".
    Choose disconnect from iTunes and the library should be gone from your Sources.

  • EDN:  subscribe to the same event deployed on different domain/Servers

    We are working on use case where in we would like to publish an Event from an ADF application . We would like to subscribe to the same event deployed on different domain/Servers than the servers on which ADF Application deployed. We would like to get more information on the configuartion of Foreing JNDI for the Business events for this use case. in the documentation it was mentioned, it is possible but not much details were provided.
    So far all I have to go on is: http://download.oracle.com/docs/cd/E21764_01/integration.1111/e10224/obe_intro.htm#BABHBGAG

    We are working on use case where in we would like to publish an Event from an ADF application . We would like to subscribe to the same event deployed on different domain/Servers than the servers on which ADF Application deployed. We would like to get more information on the configuartion of Foreing JNDI for the Business events for this use case. in the documentation it was mentioned, it is possible but not much details were provided.
    So far all I have to go on is: http://download.oracle.com/docs/cd/E21764_01/integration.1111/e10224/obe_intro.htm#BABHBGAG

  • How do I get videos and pictures taken in the same event to show in a slideshow in the order they were taken?

    How do I get videos and pictures taken in Photos and the same Event to show in the order they were taken? Pictures and videos are seperated with videos at the end of both Photos and the Event.

    You're welcome.
    What's likely happened is that when you transferred the video to the new machine they lost their dates.
    Photos use the Exif metadata to record the date and time of the shot. This is quite different from the date and time of the file, which can change as the file is copied from place to place. Video doesn't have Exif, and so iPhoto uses the file date, and that's changed.
    Simply, there's no absoultely reliable way to date video.
    Try assign dates with the Batch Change command under the Photos menu.

Maybe you are looking for

  • How to create multiple tables in Adobe air?

    Hi, I am using Flash CS5 coding for adobe air 2.0. How do you create a database with multiple tables and link them together? I know how to do it in SQL just can't seem to get it to work in Flash CS5 Adobe air. The following is ONLY an example of a da

  • Error in Burning Music CD

    Burning CDs yesterday with nary a glitch. Suddenly start receiving error that "Songs in this playlist will not fit on one CD". The problem is this list in question is LESS TIME than previous lists? So why I am getting this message now AFTER burning o

  • Problem with CFimage / PNG images

    I have a problem saving PNG images from another server, for example itunes, some work, some don't The following image will open fine in my browser -> http://a576.phobos.apple.com/us/r30/Purple/v4/de/60/bb/de60bb7f-8995-4007-cfec-1b0a472fa36 7/icon.pn

  • New camera raw support in 10.5.7

    But unfortunately still no Leica D-LUX4 or Panasonic LX3.

  • BOM Child Item Qty

    Hi Experts, In BOM Child Item Quantity i need to exceed decimal points over 3 decimals. i.e. currently when i put weight for child item  as 0.115 gms it will return in 0.12 gms. and its making atleast 10-15 % variation in Qty. Plz suggest for same. a