I am making text based operating system in java and i am wondering if i should use threads. It has a GUI but you type commands and press a button to enter them. Then it spits back out text in a textArea. When should i use threads and how do i use them? Do i need to use threads? I don't really know how to use them and when to use them!
Asked
Active
Viewed 117 times
-2
-
7You aren't 'making an operating system in Java'. You are writing an application. – user207421 May 24 '12 at 01:46
-
You never know. This could be the beginnings of the next incarnation of Unix. – Hovercraft Full Of Eels May 24 '12 at 02:15
1 Answers
1
Use threads when you don't want the GUI to lock up. For instance, if you have (or foresee) a "cancel ongoing operation that seems to be stuck" button, then that operation better be going on in a separate thread or else your cancel button will be part of what's stuck.
Also, in some environments (e.g., smart phones), if the GUI of a Java program locks up, the operating system will kill the program.
To learn about threads in Java, take a look at the Concurrency tutorials.

Ted Hopp
- 232,168
- 48
- 399
- 521
-
How would i implement threads into my program? I know how to make them but not how to put them to use! – mrspy1100 May 24 '12 at 21:51
-
@mrspy1100 - The concurrency tutorials cover a lot of that ground, including lots of examples. The particulars depend on the architecture of your program. For instance, Swing has lots of tools to allow a background (worker) thread to post events to the main (user interface) thread. Go through the tutorial and it should get you up to speed. – Ted Hopp May 24 '12 at 22:33