Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Threading Techniques & Concepts

When using threads I sometimes visualise them as weaving together 3 or more dimensional interconnections between Objects in a Spatial context. This isn't a general use case scenario, but for what I do it is a useful way to think about it.

Are there any APIs which you use which aid threading?

Have you used threads in a manner which doesn't conceptualise as thread being a process?

like image 579
Ande Turner Avatar asked Oct 10 '08 08:10

Ande Turner


People also ask

Which method is best for threading in Java?

If you want to implements or extends any other class then Runnable interface is most preferable, otherwise, if you do not want any other class to extend or implement then Thread class is preferable.

What is Java threading?

Threads allows a program to operate more efficiently by doing multiple things at the same time. Threads can be used to perform complicated tasks in the background without interrupting the main program.


1 Answers

Are there any APIs which you use which aid threading?

You mean appart from java.util.concurrent? FunctionalJava got some constructs which aid in concurrent programming, as described in a multipart tutorial that starts here.

Have you used threads in a manner which doesn't conceptualise as thread being a process?

Yes, to the extent that threads doesn't conceptualise at all. Take an asynchronous task-runner for instance. It uses threads under the covers but I don't see them and I don't care about them. They are fully managed by the task-runner.

Under the covers, it is all just threads, but when we stop caring about the individual thread and just think about them as a number of slots where you can somehow put code in and have it run for a period of time, then that is when we start to reach for a higher level of abstraction.

Agents/Actors is a common way to do this. An Actor is like a thread that has a lump of state, and then you can send it some code and say "do this to your state when you have time" or something along those lines.

like image 172
Chris Vest Avatar answered Oct 11 '22 12:10

Chris Vest