Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
JavaAPI
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Multi-Threading Support== Im java.lang package existiert die Klasse Thread. Threads can be in one of four states: *new *runnable *blocked *dead Ein Thread ist entweder ein User-Thread oder ein Daemon-Thread, wobei erstere das Beenden der JVM verhindern. Alle Objekte, die in einem Thread laufen sollen, müssen das Interface Runnable implementieren, das als einzige Methode run() enthält. Dieses implentierende Objekt wird einem Thread-Objekt im ctor übergeben und dann dessen start()-Methode aufgerufen. Eine Alternative ist die Klasse Thread zu spezialisieren, hat aber den Nachteil, daß diese Klasse von Thread erben muß, somit nicht von anderen Klassen erben kann und die Funktionalität nicht unbedingt erweitert. Daher ist die Realisierung mit dem Runnable Interface zu bevorzugen. Das Erzeugen eines Threads ist eine sehr aufwendige Angelegenheit, daher ist eine Thread-Pooling Lösung anzustreben.First methods can be declared as synchronized (see 1.11.11.2). Additionally java provides the synchronized statement to protect critical section by '''synchronized''' '''('''<expression>''')''' <statements> <expression> is an expression the must resolve to an object or an array. The synchronized statement attempts to acquire an exclusive lock for the object or array und garantiert, dass nur ein Thread auf das Objekt zugreift. Synchronität wird durch ein lock auch monitor genannt, daß für jedes java object und für jedes java class object existiert, verwaltet wird. Angeblich ist die Synchronisation über Methoden etwas schneller als über blocks. Die class Synchronisation kann auch durch '''\\''' '''synchronized''' '''('''<ClassName>'''.class)''' <statements> erreicht werden. Beim Zugriff auf static variables ist besondere Vorsicht geboten, da es durchaus möglich ist, daß zwei Instanzen, die in unterschiedlichen Threads verwendet werden, auf diese eine statische Variable zugreifen. Deshalb gibt es ein per-class lock, der wiederum nur static Methoden lockt. Außerdem besitzt die Klasse java.lang.Object die Methoden wait(), notify() und notifyAll(). ===Timer=== import java.util.Timer; import java.util.TimerTask; class MyTask extends TimerTask { public void run() { ... } } Timer t = new Timer(); t.schedule(new MyTask()); For every Timer there is a thread, which executes the tasks.
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width