Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Thread waiting  (Read 1218 times)
0 Members and 1 Guest are viewing this topic.
Offline harry@dayfamilyweb

Junior Member





« Posted 2006-04-28 00:21:03 »

how do you make a class wait for a thred to have run for a certan amount of time
so i whant to
Thread.start()
wait for thread to get to line 500
do somthing whith thread;
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2006-04-28 00:30:10 »

Excuse me, but how about buying a good Java book?

You'll learn pretty much nothing this way, seriously! Do yourself a favor.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline harry@dayfamilyweb

Junior Member





« Reply #2 - Posted 2006-04-28 00:33:31 »

i did and i got board  Grin the chapter on threading explains how to make a thread wait for stuf or sleep but not on how to make a class wait for a thread to run() or start() Cry Cry Cry Cry oh yer and i have leart alot on these forms Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #3 - Posted 2006-04-28 00:51:04 »

That's because you can't make a class wait. A class doesn't have its own flow of control. A thread does. Threads can wait for each other.
Offline Mr_Light

Senior Member




shiny.


« Reply #4 - Posted 2006-04-29 14:50:45 »

that and start and stop are depricated.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #5 - Posted 2006-04-29 16:14:49 »

<pedant>start() is very much not deprecated. stop() and suspend() are</pedant>
Offline Mr_Light

Senior Member




shiny.


« Reply #6 - Posted 2006-04-29 22:01:23 »

your quite and very right


/hides his face.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline xiaohouzi

Junior Newbie





« Reply #7 - Posted 2006-04-30 05:16:35 »

You might want to check out a simple example on how threads work first.

There's a good example at
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter08/demoClock.html
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2006-04-30 12:23:48 »

how do you make a class wait for a thred to have run for a certan amount of time
so i whant to
Thread.start()
wait for thread to get to line 500
do somthing whith thread;

Actually, I think this is a good question, since it's a real-life one that often isnt answered by the books (because they're too academic). Although the best answer would be "use co-routines", since those aren't natively in java lets not go there Smiley.

The correct way would be to use Object.wait() and Object.notify() (that's enough for you to google - but the simple explanation is you pick *any* object that is accessible to both your main class and to the thread, and when you want the class to start waiting you call (the object).wait(), and when the thread reaches line 500 you have it call (the object).notify().

Java lets you use any object for htis, soyou can have an infinite number of wait / notify pairs running in tandem at any one time. For example, you might create a String with the value "wait for thread to reach line 500" and use that as your object.

malloc will be first against the wall when the revolution comes...
Offline Mr_Light

Senior Member




shiny.


« Reply #9 - Posted 2006-04-30 12:49:33 »

there is no fixed relation to lines and time. Perhaps he was as uncarefull as I was in my first reply, but that hints. also in conjunction with thread start() doing nothing till line 500 why not simply call start() at line 500?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!