Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problems cleaning up an applet  (Read 1342 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Devvie




Java games rock!


« Posted 2004-02-22 13:30:37 »

i have an applet using one thread for drawing graphics.
the problem is when i use appletviewer with console window in background and i close the applet window, the onsole frame seems to lock for a while.


the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
        public void start()
      {
            if (runner == null)
            {
                  runner = new Thread(this);
                  runner.start();
            }
            System.out.println("Applet : Start");
      }

      public void stop()
      {
            System.out.println("applet stop");
            runner = null;
      }
     
     
      public void destroy()
        {
             offscreen.dispose();
             System.out.println("destroyed");
         }


im in sorrow that the thread doesnt get destroyed properly.
Offline tom
« Reply #1 - Posted 2004-02-22 14:14:09 »

Do you exit your run() function when runner is set to null? You must do something like this:

1  
2  
3  
4  
5  
public void run() {
   // exit game loop when stop() is called.
   while (runner != null) {
   }
}


When you exit the run() function the thread will stop.

Offline Serethos

Junior Devvie




Java games rock!


« Reply #2 - Posted 2004-02-22 15:09:51 »

i added the code line, but finishing the applet still seems to take to long.  its only a matter of ~10 sec. but if i run a applet with no extra thread it clears up immediately
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2004-02-22 15:47:18 »

The only other thing I can think of is seting runner to be a daemon thread:
1  
2  
3  
runner = new Thread(this); 
runner.setDaemon(true);
runner.start();


From setDaemon javadoc: "The Java Virtual Machine exits when the only threads running are all daemon threads."

Offline nonnus29

Senior Devvie




Giving Java a second chance after ludumdare fiasco


« Reply #4 - Posted 2004-02-22 18:59:47 »

I always call stop() on the animation thread and I've never seen the problem you describe.

1  
2  
3  
4  
5  
6  
7  
public void stop ()  {
            if (animation != null)  {
                  animation.stop();
                  animation=null;
            }
           
}
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #5 - Posted 2004-02-22 19:10:02 »

Quote
I always call stop() on the animation thread

tsk... tsk...

Using deprecated methods... sigh..

You should interrupt the animation thread and let it exit gracefully.
I usually have something like this for my animation loop:

1  
2  
3  
4  
5  
6  
7  
8  
9  
try {
  while( !Thread.interrupted() ) {
    doStuff()
    Thread.sleep( x );
  }
}
catch(InterruptedException e) {
  // just exit
}


In the applet stop() method:
1  
2  
animThread.interrupt();
animThread.join();

Offline nonnus29

Senior Devvie




Giving Java a second chance after ludumdare fiasco


« Reply #6 - Posted 2004-02-23 02:57:07 »

Quote
Using deprecated methods... sigh..


Oops, I didn't know stop() was deprecated;  I wondered why I kept getting those deprecated warnings, but didn't care enough to compile with the correct flag to see what it was  :-/ .  Yes, I'm lazy like that....
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!