Skip to main content
gamedev.net
🔒 Locked

java - multithreading

Started by CodeEnthusiast Dec 24, 2004 at 9:54 PM 2 replies 1.2k views
Original Post
CodeEnthusiast
CodeEnthusiast
I just started Java and have a question about its multithreading. I've heard it is built-in, is that correct? And also, if it is, do I need to do anything special to "activate" this multithreading like in C or C++ or does it automatically do that for you? Any answers would be appreciated.
capn_midnight
capn_midnight
Multithreading is always enabled all the time, in fact it is essential to the JVM as it processes certain things on different threads.

Two ways to write a thread, overload the Thread class or implement the Runnable interface. I suggest the latter.

some class must implement the Runnable interface. You pass an instance of that class to the constructor of the Thread class. You then call the start method of that instance of the Thread class. That's all you have to do, it's really easy.

also, this belongs in the Java Forum.
kSquared
kSquared
Quote:
Original post by CodeEnthusiast
I just started Java and have a question about its multithreading. I've heard it is built-in, is that correct? And also, if it is, do I need to do anything special to "activate" this multithreading like in C or C++ or does it automatically do that for you? Any answers would be appreciated.

Be careful: Java threads are frequently the source of many difficult-to-find bugs. This is also true of any asynchronous/nondeterministic programming model, of course, but Java threads have their own unique problems. Googling on Java threading bugs should reveal some choice examples.
- k2 "Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ<

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.