Thread in infinite loop, won't allow anything else to happen...help appreci

Basically, i'm trying to make a basic traffic simulator, and learn java at the same time, so bare with me...
I want a couple of threads to run concurrently in the applet, but am having touble. Basically one starts inside the run() and works fine, but the other wont...infact nothing after the first thread will run (i.e. if the repaint() goes after the end of catch{}). The source is a bit of a mess with no comments, but its all really basic so should be easy for even the elementary java programmer to understand.
I know the second thread (well what i hope is a second thread) doesn't actually do anything other than output a line that could be done by the first thread, but its just proof of concept for now, i will put stuff in there later.
source, class and html are here:
http://www.soton.ac.uk/~tr403/traff/
also the slider in the bottom right doesn't appear in the browser unless you click on it, but in the applet viewer it comes up...why is this? its at the bottom of my priorities at the mo, but its puzzling, and obviously something really elementary.
Any help MUCH appreciated, its for my dissertation which has got be to handed in on may 11th ;)
This the run bit, initated from the start [method? not sure on terminology yet]
public void run()
              Thread carmove = Thread.currentThread();
               try {
               while (carmove != null){
               Thread.currentThread().sleep(carsptimeout);
               xcount++;
               repaint(0,144,300,5);
               if (xcount == maxlength1){
                    xcount = 0;
            catch (InterruptedException e){}
                 Thread sysline = Thread.currentThread();
               try {
                    while (sysline != null){
                    Thread.currentThread().sleep(carsptimeout);
                    System.out.println(xcount);
               catch (InterruptedException e){}
     public void stateChanged(ChangeEvent e)
          tempreadout.setText
               (" " + (slider.getValue()));
          carsptimeout = 100 - (int)slider.getValue();
         public void update(Graphics g)
              paint(g);
        }

This sounds like something i can do...not sure how
its gonna effect the slider at the bottom but will do
it anyway.Think of your applet as a bunch of cards on top of each other.
+----------------------+
| APPLET               |
|                      |
|                      |
|  --------          |
|  | button |          |
|  --------          |
----------------------Each card call the paint on all its childern. You override the paint, so it it does not call "paint" on its childern. By moving the draw into a different JPanel, which has no childern, the fact that you don't ask for its childer to be drawn does not matter.
| Applet               |
| -----------------  |
| |DrawTraficlights |  |
| -----------------  |
|                      |
|  --------          |
|  | button |          |
|  --------          |
Any ideas on my threads?Redesign.
Create a class for object type in your world. Only "extend" a different class if that makes sence.
What is a "sysline"?
Why is trafic light moving cars forward?

Similar Messages

  • I am a student trying to purchase creative card with a maestro card but won't allow anything other than master card or visa, is there any way around this?

    I am a student trying to purchase creative cloud with a maestro card but won't allow anything other than master card or visa, is there any way around this?

    No, not that I know about... but you might check the credit card page to see if there is an option
    Change/Verify Account https://forums.adobe.com/thread/1465499 may help
    -Credit card https://helpx.adobe.com/utilities/credit-card.html

  • Am replacing airport extreme with Time Machine and want to upgrade from Tiger to Snow leopard. Am told I should manually back up into T Machine before OS update but set up utility won't allow anything with OS below 10.5 and I'm 10.4.11. What to do?

    Am replacing airport extreme with Time Machine and want to upgrade from Tiger to Snow leopard. Am told I should manually back up into T Machine before OS update but set up utility won't allow anything with OS below 10.5 and I'm 10.4.11. What to do?

    I think you mean you are replacing your Airport Extreme with a Time Capsule. Time Machine is software integrated into OS X 10.5 & 10.6 used to automatically backup a system to an external HD. Time Capsule is an Airport Extreme that has a hard disk integrated into it that can be used for storage or  as a Time Machine backup drive.
    Because you are currently on Tiger 10.4.x you can backup to a external HD using SuperDuper or Carbon Copy Cloner. Having a backup is very wise before doing any major system update. After  you have created the backup and have successfully upgraded to Snow Leopard you can still use the external HD for many things. The strategy I'd recommend is to use the new Time Capsule as your Time Machine backup and then use the external HD as backup using SuperDuper or CCC. Redundant backups is wise because backups can (and do) fail too! In addition both SD and CCC are bootable clones, this is useful in that if your internal HD crashes you can boot from a cloned drive and continue working until the internal HD is replaced.
    Below are some links to some articles from MacWorld, I would recommend reading them where you find a common theme, redundant backups. Backup Plan I, Backup Plan II & Backup Plan III.
    Roger

  • My apps won't download to my iPad but will to my phone. When I put it my password, it just stops and won't do anything else????

    My apps won't download to my iPad but will to my phone. When I put it my password, it just stops and won't do anything else????

    Unless you have a copy of the iPod backup file from the previous computer installation you are out of luck. If yo have that file move it to your computer and restore the iPod from that backup.  Otherwise, you will have to restore the iPod to factoery defaults/new iPod and lose all your app date. That is the way it is since the iPod sees the computer as a new computer/iTunes library.  That backup file is located:
    Mac: ~/Library/Application Support/MobileSync/Backup/
    Windows XP: \Documents and Settings\(username)\Application Data\Apple Computer\MobileSync\Backup\
    Windows Vista and Windows 7: \Users\(username)\AppData\Roaming\Apple Computer\MobileSync\Backup\

  • Have recently installed windows 7 32bit operating system and it won't allow me to install iTunes, help??

    Have recently installed windows 7 32bit operating system and it won't allow me to install iTunes, help??

    Let's try the following document with that one:
    iTunes: Windows reports that "iTunesSetup.exe is not a valid Win32 application"

  • I just installed Readdledocs on my ipod, and now when I launch the app, I get a screen which says "downloading message" and the app freezes and won't do anything else.  How can I get the app to function again?

    I just installed Readdledocs on my ipod, and now when I launch the app, I get a screen which says "downloading message" and the app freezes and won't do anything else.  How can I get the app to function again?
    This happened after I tried to get Readdledocs to open an epub file which I created in Calibre.

    This is a followup to my own posting above.
    Thanks to Dave Sawyer for posting information about re-downloading an app which has been deleted.  I deleted the app from iTunes.  Then, when I synched, iTunes asked me if I wanted the items on my ipod touch copied back into iTunes.  I said yes and then synched.
    Readdledocs is now working again.  It is no longer frozen.  However, I have learned my lesson.  I will download only pdf's from now on.  I don't think it works so well with epub files.  The text reflow feature of Readdledocs is exactly what I need to use for my work documents on my ipod touch.

  • TS3274 my ipad has a black screen and the apple logo and won't do anything else. I have tried to reset it but to no avail.

    My ipad has a black screen and the apple logo and won't do anything else. I have tried to reset to no avail.

    Try and force iPad into Recovery Mode
    1. Disconnect the USB cable from the device, but leave the other end of the cable connected to your computer's USB port.
    2. Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to turn off.
    3.While pressing and holding the Home button, reconnect the USB cable to the device. The device should turn on.
    4. Continue holding the Home button until you see the "Connect to iTunes" screen. When this screen appears, release the Home button. iTunes should alert you that it has detected a device in recovery mode. Click OK, and then click Restore to restore the device.
    Note: Data will be lost. You may have to repeat the above many times.

  • My iPad demands that I sign into iMessage.  It will not accept my password and will not allow anything else to operate.

    My iPad began by demanding I sign into iCloud.  (I had recently changed my Apple account password.)  I entered the password and then iMessage demanded my password for the same account.  It would not accept my password and it keeps popping up, not allowing anything else to operate on the iPad. How do I fix this?

    Content and Apple IDs -
    Content is forever tied to the Apple ID that bought it. Apple does not transfer content from one Apple ID to another. Apple does not merge Apple IDs. You will never be able to access your content bought with another Apple ID with a new Apple ID.

  • My Ipod Touch is not responding.  I have restored, I have recovered, I have followed the troubleshooting tips. It is still frozen and I can't turn it on or off.  Is there anything else that can help?

    My Ipod Touch is not responding.  I have restored, I have recovered, I have followed the troubleshooting tips. It is still frozen and I can't turn it on or off.  Is there anything else that can help?

    Let the battery fully drain. After charing for at least an hour try a reset and restore.

  • Stopping a Thread in Infinite Loop

    I've read several articles on how to stop Threads, and all of them point to using Thread.interrupt(). The problem right now is what happens when the thread is in an infinite loop. For example:
    class A implements Runnable
        public void run()
            while(!Thread.currentThread().isInterrupted())
                  while(true);
    //in other class's main method:
    Thread a = new Thread(new A());
    a.start();
    a.interrupt();The a.interrupt() call only sets the isInterrupted flag in Thread, but it does not terminate the thread as a.stop() would. However, stop() throws a ThreadDeath exception that I would not want to have to deal with. Is there any way to stop this infinite loop thread safely?
    Thanks in advance!

    No need to get snitty. You certainly did not make clear that you are not a newbie at programming. Plenty of newbies who barely have a grasp of the language fundamentals post thread questions here. I thought I did address the question at hand. It seems I misunderstood what you were asking.
    The only way to safely stop that inner loop is like so: while (...) {
       while (!done) {
    }where done is volatile, or all access to it is sychronized on the same lock (meaning you'd sync the !done check above as well).
    If you can't do that, and it's stuck at while (true) and you can't modify the body of the inner loop to check done, then you're SOL.
    (I suppose it's conceivable that 1.6 or 6.0 or whatever it's called will introduce some new safe way to stop that thread, but I haven't heard anything about it.)

  • Listeners, load a class on startup and creating threads in infinite loop

    This is an identical post to the one I made in the jsp forum. I do this as I know, being a regular here, that there are equally good people(in j2ee web application development) in both these forum, but many of them stick to their particular forums of choice - jsp / servlets.
    I was wondering if there is any means by which I could launch my own class when tomcat starts (in the same jvm).
    1. I need one or more Thread/TimerTask because the requirement is such that the application would have continous data drops (in the form of logs) which has to be picked up, parsed and pushed into a db. Another part of the application reads the data from the db on requests (http) and displays it over the web. The thread has to poll for arrival of new logs and then hand it over to a framework for parsing and inserting the parsed data to a db.
    2. I know that I can possibly use a servlet with a load-on-startup value greater than 1 and code my requirement into the init method. However, using a servlet for a functionality different from servicing http requests has me worried. (valid ?), not to mention the fact that Iam very uneasy about creating threads from within Servlets.
    3. I googled hard and found that I could probably use a tomcat specific context lifecycle listener.
    4. I could also possibly use the servlet api - the ServletContextListener.
    5. I have rejected #2 and settled on either #3 or #4 - the ServletContextListener or Tomcat specific Lifecycle Listener, though the later, as I said binds me to Tomcat (which is ok for me). Are there any other specific (dis)advantages of using either especially when I have to create threads from within them (on context startup)? Other than memory leaks, killing the thread objects & associated resources on context shutdown, is there anything else that I need to watch out for while using threads.
    6. I wonder is there is there a plain startup hook available in tomcat (rather than listeners) - from where I can launch a class that starts a thread in the same jvm as tomcat's ?
    Thanks In Advance,
    Ram.

    Anybody ? Sorry for bumping up.
    Thanks,
    Ram.

  • I just updated firefox TODAY 8/17/11 and after the update i can't open firefox unless i restart my computer or i delete going to windows task manager and process, also i can't open a new window, it won't allow it. please can you help me

    I just updated firefox TODAY 8/17/11 and after the update i can't open firefox unless i restart my computer or i delete firefox going to windows task manager and process, also, i can't open a new window, it won't allow it. please help me, everything works on IE, Google Chrome and Safari, everything went wrong after the update

    Hey Elaine07!
    I have an article here that can help you with that issue. This article will help you make sure you have uninstalled iTunes correctly and help you troubleshoot the launch issues you are seeing:
    iTunes for Windows Vista or Windows 7: Troubleshooting unexpected quits, freezes, or launch issues
    http://support.apple.com/kb/ts1717
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

  • After updating my iPad it now shows iTunes symbol and charger cable. It won't do anything else please help

    AAfter updating my iPad 4 wwith iOS 8 it now shows iTunes symbol and charging cable but it won't let me do anything else please help

    Hello nicholafrombelfast,
    Thanks for using Apple Support Communities.
    This screen on your iPad indicates that the device is in recovery mode and will need to be plugged in to your computer with iTunes to restore the device back to its factory settings.  Please see the following articles for more information.
    If you can't update or restore your iPhone, iPad, or iPod touch
    Use iTunes to restore your iOS device to factory settings
    Take care,
    Alex H.

  • HT201263 My phone is staying on Step 4 it won't even open Itunes.  Please help!  What is wrong with my phone?  It stays on that screen and won't do anything else.

    My phone is staying on Step 4 it won't even openn ITunes.  Just stays on that screen and does nothing else!  Please Help! 

    Have you tried holding the power and home button until it turns off?

  • MySQL Service first time use: in infinite loop, won't start and can't stop

    Log says: "The host 'DOMAIN.COM' could not be looked up with resolveip."
    It says that is not a problem just use IP addresses. Included just FYI.
    Then: "Installing MySQL system tables...
    Installation of system tables failed!"
    I suspect this is why I am in an infinte loop.
    In setup I chose a Root Password and changed the default database location to be on my second HDD, plus I allowed Network connections.
    Now it is in the starting state always, looping with the same error over and over and creating bin files in my chosen DB area. I can't stop it from the GUI (not tried from command line as want to be sure I get right command - help there would be welcome). I can't remove the service as it puts itself right back in there straight away. Rebooting doesn't help as it starts up automatically. Please help!

    I am putting up my "solution" as it is for now. After quite a bit of research, I discovered that my problem was caused by my selection of a database location that had a space in the path. I was using the Server Admin GUI and would have hoped that such a tool would know the MySQL can't have spaces in the path and it would have told me not to set it to one that did have space in the path, but it seems not. So once that was discovered I also thought changing the path in the GUI would fix it, but alas, it did not. After quite a bit more research (I learned quite a lot, during this, but there is still a lot more to learn) I worked out that the plist file used by the daemon which starts services had not reflected the changes I had made in the GUI. So after more checking to make sure it was Ok to do so, I edited the file to reflect the database location and PID file location to be the default of /var/mysql. MySQL sprang to life and seemed fine, but unfortunately the GUI was messed up still. So a little more research led me to the serveradmin command that can be used in place of the GUI and I have now been able to turn off the service (I only started it out of curiosity and don't yet need it). So as I say - a kind of "solution" because actually my GUI appears to be broken, but I am able to use my machine again without it looping incessantly.

Maybe you are looking for