Can't get my threads to run at the same time  :-(

Hi,
I hope someone can help me. I have an two instances of an object that extends thread. In it's run method, there is a while loop that iterates while an int x (that starts at about 450) is not less than 0.
In the while loop there is an x--; statement.
Also inside the while loop is a call to yield();
Also is a call sleep(5);
Also in the while loop is a statement something like "System.out.println(x);"
The int controls the vertical position of an icon (a JLabel) on the screen.
In the class that has the main method, two instances of the thread object are created one after the other and run one after the other, although the program keeps running the first one until it has finished before running the second one!
For example, the code looks something like this:-
o1.run();
System.out.println("o1 running");
o2.run();
System.out.println("o2 running");
And the end printout (with the println call from the thread objects) looks like this:-
o1 running
450
449
448
3
2
1
o2 running
450
449
etc.
What's going on? Why won't it start running the second thread straight after the first one?
Any help appreciated!

class test extends Thread {
  private int i = 0;
  private String strMess = new String("");
  public static void main (String[] args)  {
     test t = new test("first");
     t = new test("second");
  test(String strIn){
       this.strMess = strIn;
       this.start();
  public void run(){
       while(i<5){
          System.out.println(this.strMess + i);
          try{this.sleep(200);}catch(Exception e){e.printStackTrace();}
          i++;
}output:
first0
second0
first1
second1
first2
second2
first3
second3
first4
second4
class test extends Thread {
  private int i = 0;
  private String strMess = new String("");
  public static void main (String[] args)  {
     test t = new test("first");
     t = new test("second");
  test(String strIn){
       this.strMess = strIn;
       this.run();
  public void run(){
       while(i<5){
          System.out.println(this.strMess + i);
          try{this.sleep(200);}catch(Exception e){e.printStackTrace();}
          i++;
}output:
first0
first1
first2
first3
first4
second0
second1
second2
second3
second4

Similar Messages

  • How can I get rid of multiple pictures at the same time?

    how can I get rid of multiple pictures at the same time?

    Adobe Bridge, lightroom and your file browser (windows explorer or Mac Finder) can select multiple pictures at once and then delete. If you are looking for more than that for information, you will need to be more specific at what your doing, what OS you have, and version of software your using. If necessary post screen shots so we can see what your doing. The more information we have the more detailed of an explaination can can give back to you.

  • Can a vodcast and a photocast run at the same time ?.

    Hi,
    I would like have a video podcast play and a photocast run at the same time is this feasible?
    Geoff

    Since they're different apps and there's no way to sync something like that: no. Sounds like you could just do a video slideshow to me. That's supported by all major video creation apps.
    -S

  • Can't get 2 firewires to mount at the same time

    i just bought 2 500 gb externals to set up a raid, and i can get either one to show individually, but not at the same time- either by daisy chaining or using separate ports. the second will even show up if the first is off when they are daisied. i don't know for sure that i've ever used 2 at once, but am fairly certain i have. the ports all work individually- both 400's and the 800. i tried 1 800 and 1 400 at the same time, and daisied with 800 main + 400 daisy and 800 main + 800 daisy, all to no avail. nothing wrong with the cables- i cross checked. it's flakey mounting and dismounting, too (for instance, stuff disappears once dismounted and won't reappear til i reboot, even if i restart the device).
    i reformatted both drives to mac journalled. i searched and have followed the instructs to reset the firewire ports, repaired permissions (many times) zapped the pram, and shut down the comp for 15 mins, inc the power, without any other devices attached to troubleshoot each drive, all to no avail. one strange thing- even the 400 ports showed as 800's in the profiler. only one at a time will show there, as well- whatever is mounted (or the first i mount; the second doesn't show). i should note i had a drive go bad on the 800 port not once but twice in the past year, and assumed it was the drive (it was used), but now i'm wondering if the port's funky. do they go bad and how hard are they to replace?
    i don't really want to have to reload my system- i have an awful lot of software loaded and am in the middle of a busy time, plus i suck at that. i'm getting ready to add a couple gigs of ram to speed things up, too. it should be here tomorrow. i'm a retoucher and work on big files that need backed up regularly, which is why i'd like to do the raid and just work off it. i'm not on tiger- have been waiting for leopard, and was so mad when they pushed it back, since it means i have to wait on cs3, too, which really hurts my business. but i'll be darned if i upgrade now and then have to pay again in 3 months. i wish they'd offer the upgrades at half price this close (or do like other co's do and upgrade for free within a reasonable amount of time- not 7 days). any advice i haven't tried? please?
    G5   Mac OS X (10.3.9)   dual 1.7 mh; 1GB ram; 2, 250's hard drive

    ok- i will try to answer what i can, but bear with me- i'm really good at what i do, but this ain't it. some of what you asked i don't know where to find the answers to. to start, the drives are western digital my book pros, 500 gb each. they support firewire 400, 800 & usb. the old drive that failed twice was a lacie 500 gb, too (with the metal case- don't know the official name off the top). i have pro friends who have similar setups with no issues (and am seeking advice from them as well).
    i have a 1.8 mh dual, but i do have 8 ram slots, and i wouldn't want to deal with a mac book pro. retouching just doesn't work well with laptops, and i don't travel so i'd have no need. when i'm ready to get a new system, i want an intel quad. hoping i can push that off a year or 2, with the ram additions and raid.
    i'm not using pci fw800 card adapter. my friend says he thinks a hardware raid solution like the la cies that run off a SATA card would work better, but he was curious if i can do what i want with the PCI-X card and the drives i have (since i don't want to return them or spend huge amounts more of moolah). so, do you know if i did get one if it would make the raid work? or would a 400 card be better? i'm not a photog filling a tb with each job (which my other refs are) so i don't need the huge volume of space that they do. but i do work on some pretty big files at times, and it can add up quickly. i think a terabyte raid would hold me for quite a while- which is why i did the 2 500's.
    when i unplugged the machine and left it down for 15 mins, i unplugged everything, inc power cord, except the mouse and monitor cable, per instructions i found through the apple site.
    normally i don't care to be on the bleeding edge and wait a little while to get new software, but it seems like i've waited so long, and leopard has so many features i think would be great. my buds agrees with you that getting the stable os is the best bet, and that i'm being too cheap. i guess that's the next step then, huh?
    here's what the profiler says in general: Machine Model: Power Mac G5
    CPU Type: PowerPC 970 (2.2)
    Number Of CPUs: 2
    CPU Speed: 1.8 GHz
    L2 Cache (per CPU): 512 KB
    Memory: 1 GB
    Bus Speed: 900 MHz
    Boot ROM Version: 5.1.4f0
    Serial Number: ********
    and specifically about the firewire:
    FireWire Bus:
    Speed: 800 Mb/sec Speed
    External HDD Device:
    Capacity: 465.76 GB
    Manufacturer: WD
    Model: External HDD Device
    Removable Media: No
    Detachable Drive: Yes
    BSD Name: disk2
    OS9 Drivers: No
    Speed: 800 Mb/sec Speed
    Unit Spec Id: 12512
    Firmware Revision: 107a
    Unit Software Version: 484944
    let me know if i answered what you wanted, and if there are more ?'s. i haven't had a chance to try both 400's at once yet since i'm mid-job that i can't close right now.
    thanks so much for your advice.

  • Can't get 2 monitors to work at the same time G4 533

    Hello all,
    I have a G4 533 Dual with the stock card in it I think it is a nvidia GeForce 2MX I have a 17 inch clear monitor It is the one that matched it new. I also have a old apple 17 inch display this is the old tan one with the colored apple on the front( I have an adapter to plug this one in). The video card has 2 ports and both monitors will work in their port but if I plug them both in at the same time the clear monitor goes out. If I plug it in first then add the older one the older one wont work. I have restarted and tried all different things the ports all work as do the monitors just not at the same time. I want to be able to see differnt things on both monitors. I also have a 733 with the same 2mx card so swaping them wont help. Can anyone tell me what I need. thanks.
    Powermac G4 533 Dual   Mac OS X (10.4.4)  

    Hi Sarkis,
    I note that this is now the subject of another thread that you started - it's better to stick with one thread per subject otherwise there's "double handling" involved in answering your issue.
    For what it's worth, the older (none core image) cards that will do extended desktop are:
    Mac Radeon ATI 8500
    Mac Radeon ATI 9000
    Mac GeForce4 Ti
    As a rule of thumb, a card with 64 mB or more will generally be able to do extended desktops.
    If you want core image support, then any card later than the ATI Radeon 9600 will do, with the ATI 9800 probably being the card of choice.
    This has been posted your other thread as well.
    Cheers!
    Karl

  • I have an Ipad mini and an iphone 4.  Can i get text messages on both at the same time?

    I have an Ipad mini and an iphone 4.  Can I get text messages to appear on both devices at the same time?

    Yes if the messages are sent to an ID which is in the receive section of Settings > Messages > Send and Receive on both devices.

  • Can B1 2005 and 2007 be run at the same time?

    I want to install B1 2007 on my server to make sure that everything runs over smoothly, then when I'm satisfied with the results, I'll just upgrade my workstations and hopefully have a seamless transition.  Are there any errors that will pop up if I install 2007 at the same time as 2005?  I have to make sure that there isn't a work outage.

    Derek,
    if you mean both version to sql server, the answer is yes, you can. If you mean to install the aplication, the answer is no, you cannot. If you want to test new version, youll have to use new computer or some virtual PC.
    Petr

  • How can I get two cameras to aquire at the same time rather than one after the other

    I've got (2) PCI-1428 cards, Two Uniq Vision cameras with power supplies, cameralink cables, and IMAQ-D6804 cables. Both cameras are being triggered by the same switch, but they are not grabbing images at the same time. Right now it is triggering one camera as desired, but the other doesn't aquire until after the time-sensitive event. On the next test, the two camera will trade these roles. I am using 2 cards, so they should acquire at the same time. How do I change it so that they grab images at the same time? Thank you for your help.
                                                      ​            Deater

    Hi Deater,
    Thank  you for your post.  Triggering from two cameras at the same time may be a little trickey, but it can be done.  There are multiple ways to tackle this problem.  If you have a RTSI cable, you can RTSI the two PCI boards together internally to lock them in HW.  You should also be able to use the triggering line on each board.
    One of the best methods for triggering multiple boards is called GenLocking.  The following Developer Zone page describes GenLocking more fully and has several examples to help you out: http://zone.ni.com/devzone/conceptd.nsf/webmain/a3​87b5c0ac6f6f4e86256c87005fcddf.
    The "HL Grab with two boards.vi" shipping example is also a good example of the code needed to trigger two individual boards in LV.  I found a similar post that may be of some help as well: http://forums.ni.com/ni/board/message?board.id=230​&message.id=2691&requireLogin=False
    Hope this helps!
    Thanks,
    Scott Savage
    National Instruments
    Applications Engineering
    www.ni.com/support

  • I am still trying to get two funtions to run AT THE SAME TIME within my vi, but to no avail.

    I am trying to capture a signal with a daq card (PCI-MIO-16E-4) WHILE I have a picture box switch back and forth between grey levels. It is absolutely necessary that they both happen simultaneously, but what is happening is that the picture box stops switching while the DAQ is capturing the signal. Can someone take a look at this and offer some suggestions, or just see if you can get this thing to work. The vi is simple and should be straight forward, right? I have had some suggestions on a previous fishing expedition, but none worked. If you try this vi, set the scan rate to 5000, and the # of scans to 15,000. P.S. I am running labview 6.1 if that makes any differenc
    e. Thanks for your attention.
    Attachments:
    Acq_N_Scans_to_File_(wdt)_with_flicker_2while.vi ‏135 KB

    Hi Planar,
    You have been trying hard!
    I am not sure the following will help, but I would like you to try it out.
    I have restructured your code to help reduce the work that is done while data is acquired.
    1) I "pre-compute" the pictures at app start-up. This way only the pictures need updated and the pictures are rendered repeatedly.
    2) I moved your config up front so it does not run while the flickering is going on.
    3) I add a check of the backlog from the DAQ that looks at the number of scans waiting in the buffer WITHOUT reading the data. Only when the requested # of scan are ready is the data read.
    4) While waiting for the buffer to fill, the daq loop will execute a wait, thereby freeing CPU for the flicker tasks.
    Your code, w
    ith my changes is attached (in LV 7.0).
    A jpg is included for non-LV-7.0 readers.
    Yes, the code is sloppy! I am woring fast and for free!
    No, I do not have DAQ hardware to test so it may NOT work right out of the box.
    I hope this helps,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Flicker.vi ‏152 KB
    Flicker.JPG ‏157 KB

  • Can PSE 6 and PSE 8 Run at the Same Time?

    I have Windows 7 and recently upgraded to PSE 8 and have had problems with Photo Mail and email attachments. I did not have email attachment problems with PSE 6 so I wonder if I can run both 6 and 8. Will there be a catalog problem? When I loaded PSE 8 the first time the catalog needed to be converted. Will this make it unstable for PSE 6?

    As requested.

  • Can I get multiple videos to run on the same iweb page?

    Hi there
    Am about to embark on a project which involves uploading several video clips + commentary to one web page - just wondered whether this is possible in iweb? And, if so, how?
    Ideally, I'd like to position them in adjacent pairs - like in the 'photo page' formats… but so they'd play in that position (is there a simple way of getting them to do that?
    Or, should I upload to youtube and embed - I've had problems trying to do that previously.
    Hope that all makes sense - and thanks in advance for your advice!

    It doesn't make sense to have more than one movie file per page unless they are tiny files.
    If you put too much stuff on a page it will take a long time to load and will probably lock up in Internet Explorer. Unless all your viewers are using Macs with Safari, you have to keep your pages real simple and/or optimize your files before upload.

  • Two processes running at the same time in Lookout

    I have installed Lookout 5.0 with 200 I/O Points onto our server computer. The application of motion control is next to the 200 I/O points through OPC PMAC server/client. Now I would like to have a second process in the same server for trouble shooting and testing without stopping the motion control process. However, this second testing process could have also many I/O points through Serial and USB ports. I assume that the total amount of I/O points of both processes will be greater than 200.I prefer to have independent processes for control and testing because access levels. Can I have these two processes running at the same time when needed?

    Hi,
    From your description you are using a third party OPC server for the motion application. You could have a second Lookout process communicating with the same OPC server with no problems, as long as you do not exceed the number of I/O points your license supports.
    Also, the process you are using for testing obviously could not overwrite datamembers (or registers if you will) that would interfere in the overall application, in other words you can test your application as long as you keep the coherency of the test.
    So the answer would be, yes it is possible, however you are still limited to the number of I/O's your license supports... You may even consider upgrade the number of I/O's you have in your license.
    Best Regards
    Andre Oliveira

  • How many threads can be running at the same time

    Hi!!
    Dows anyone knows how many Threads can be running at the same time in the JVM.
    I'm making a multi thread client-server app and I would like to know how much simultneous connections the JVM support. I'm using one Thread per connection.

    Hi, thanks to all for your answers.
    I think that I made the wrong question, as you said: "that means the number of threads currently created".
    I'm worry about this because my application is already online (It's a mail server -SMTP and POP3 server using ORACLE for the users database- ) and some other user post in the "multi-tread forum" that almost any JVM can only have 700 threads created at the same time, and I've never heard or read anything about this.
    what you mean with the stack space (memory??)
    I'm using the JavaWebServer 2.0 and a servlet to start the main Thread.
    Again Thanks to all for the answers but I think that the schapel answer is the one that solve my doubt...

  • Java threads. Are they running at the same time?

    Hello everybody. I am implementing a multiagent system in java and at some point in the program i need a specific function (from a specific class) to run at the same time in several "copies". Those functions are communicating with each other with some messages, so as you can understand not running at the same time is a big problem because of this messages.
    Below i am giving you an example of the code i am using. I would like your opinion whether those functions are running parallel or serial. If they are not running parallel what should i do? Any opinion or something that can help me would be perfect. Thanks in advance.
    //my class
    public class Agent extends Thread {
                           public void MinConflicts(Agent array[],int max_moves){//code in here}
    public static void main(String[] args) throws IOException {
                  Agent[] fbi = new Agent[num] //num is inserted by the user
                 //code here
                 for(i=0;i<num;i++){
                         fbi.start(); //starting the treads
    for(i=0;i<num;i++){
    fbi[i].MinConflicts(fbi,max_moves); //running the function that i want to run parallel
    //code here also :)

    What you appear to be doing here is creating an array of Thread references (which I hope at some point gets populated with actual Thread object references!)......because your first loop is wanting to cycle through each array slot starting the referenced Thread. Then the next loop iterates through the array again, this time calling the method for each Thread object.
    Assuming that you do populate the array, what this code will do is start each Thread which, I believe, will start and immediately terminate because run() has not been over-ridden. The second loop winds up calling the method for each Thread in the array. You are actually calling it from the main thread though. So, as previously advised, I think that you will run each method sequentially.
    The direction that I would head with this is to override run() in your agent Thread and have that run() method call the MiniConflicts() method. Then, in your main routine you can do away with the second for loop. The looping start will start all of the individual threads and they will execute the run() method......which in essence will be executing your MiniConflicts method.
    This reply is NOT a total design... I am sure that there are holes to be filled... but I think that will get you headed in the right direction.

  • How can I get my clock to remain on the correct time when starting bootcamp and windows XP? wireless option is not available.

    How can I get my clock to remain on the correct time when starting bootcamp and windows XP? wireless option is not available.

    Have a look at solutions in here https://discussions.apple.com/message/10689317#10689317
    Regards
    Stefan

Maybe you are looking for