Blender Animation
www.blender.org
Sonntag, 30. November 2008
EE3206/EE5805 Java-thread-5
EE3206/ EE5805 Java Programming and Applications
14.3.2 static synchronized mtehods,
notes from Gosling etc. "The Java progamming Language"
1. A static synchronized method acquires the lock of the Class object for its class. If static data is shared between threads then access to it must be protected by static synchronized methods.
2. Acquiring the Class object lock in a static synchronized method has no effect on any objects ofthat class.
3. You can still invoke synchronized methods on an object while another thread holds the Class object lock in a static synchronized method, only other static synchronized methods are blocked.
14.3.2 static synchronized mtehods,
notes from Gosling etc. "The Java progamming Language"
1. A static synchronized method acquires the lock of the Class object for its class. If static data is shared between threads then access to it must be protected by static synchronized methods.
2. Acquiring the Class object lock in a static synchronized method has no effect on any objects ofthat class.
3. You can still invoke synchronized methods on an object while another thread holds the Class object lock in a static synchronized method, only other static synchronized methods are blocked.
Samstag, 29. November 2008
The Java mind-set
The java mind-set
You must read Gosling etc 's "the Java programming Language".
It javalizes you on how to act in a java way.
The java mind-set, whether it is good or bad likes a pair of goggles put on your eyes.
You must read Gosling etc 's "the Java programming Language".
It javalizes you on how to act in a java way.
The java mind-set, whether it is good or bad likes a pair of goggles put on your eyes.
EE3206/EE5805 Java thread-4
EE3206/EE5805 Java Programming and application
notes on 14.3.1 Synchronized methods
excerpted from the "The Java Programming Language, 4th ed."
1. Synchronization forces execution of the two threads to be mutually exclusive in time. On the contrary, unsynchronized access does not wait for any locks but proceeds regardless of locks that may be held on the object.
2. Locks are owned per thread, so invoking a synchronized method from within another method synchronized on the same object will proceed without blocking, releasing the lock only when the outermost synchronized method returns.
3. This per-thread behavior prevents a thread from blocking on lock it already has, and permits recursive method invocations and invocations of inherited methods which themselves may be synchronized.
4. The constructor does not need to be synchronized because it is executed only when creating an object, and that can happen in only one thread for any given new object.
5. Access to the field must be synchronized. With the synchronized declaration, two or more running thread are guaranteed not to interfere with each other.
6. There is no guarantee as to the order of operations. If the balance is queried about the same time that a deposit occurs, one of them will complete first but you cannot tell which.
7. You can ask whether the current thread holds the lock on a given object by passing that object to the Thread class's static holdsLock() method, which returnstrue if the current thread does hold the lock on that object.
Eg. assert Thread.holdsLock(this);
8. When an extended class overrides a synchronized method, the new method can be synchronized or not. The superclass's method will still be synchronized when it is invoked.
9. If the unsynchronized method uses super to invoke the superclss's synchronized method, the object 's lock will be acquired at that time and will be released when the superclass's method returns.
notes on 14.3.1 Synchronized methods
excerpted from the "The Java Programming Language, 4th ed."
1. Synchronization forces execution of the two threads to be mutually exclusive in time. On the contrary, unsynchronized access does not wait for any locks but proceeds regardless of locks that may be held on the object.
2. Locks are owned per thread, so invoking a synchronized method from within another method synchronized on the same object will proceed without blocking, releasing the lock only when the outermost synchronized method returns.
3. This per-thread behavior prevents a thread from blocking on lock it already has, and permits recursive method invocations and invocations of inherited methods which themselves may be synchronized.
4. The constructor does not need to be synchronized because it is executed only when creating an object, and that can happen in only one thread for any given new object.
5. Access to the field must be synchronized. With the synchronized declaration, two or more running thread are guaranteed not to interfere with each other.
6. There is no guarantee as to the order of operations. If the balance is queried about the same time that a deposit occurs, one of them will complete first but you cannot tell which.
7. You can ask whether the current thread holds the lock on a given object by passing that object to the Thread class's static holdsLock() method, which returnstrue if the current thread does hold the lock on that object.
Eg. assert Thread.holdsLock(this);
8. When an extended class overrides a synchronized method, the new method can be synchronized or not. The superclass's method will still be synchronized when it is invoked.
9. If the unsynchronized method uses super to invoke the superclss's synchronized method, the object 's lock will be acquired at that time and will be released when the superclass's method returns.
EE3206/EE5805 Java thread-3
EE3206/EE5805 Java Programming and Applications
notes on 14.3 Synchronization, from "The Java Programming Language":
1. We need to avoid interleaved operation that can corrupt the data. Such potentially interleaving actions are termed critical sections or critical regions, and you prevent interference by sychronizing access to those critical regions.
2. It is solved by acquiring a lock on an objet. Threads cooperate by agreeing to the protocol that before certain actions can occur on an object, the lock of the object must be acquired.
3. Acquiring the lock on an object prevents any other thread from acquiring that lock until the holder of the lock receives it.
4. Every object has a lock associated with it, and that lock can be acquired and released through the use of synchronized methods and statements. The terms syschronized code describes any code that is inside a synchronized method and statement.
notes on 14.3 Synchronization, from "The Java Programming Language":
1. We need to avoid interleaved operation that can corrupt the data. Such potentially interleaving actions are termed critical sections or critical regions, and you prevent interference by sychronizing access to those critical regions.
2. It is solved by acquiring a lock on an objet. Threads cooperate by agreeing to the protocol that before certain actions can occur on an object, the lock of the object must be acquired.
3. Acquiring the lock on an object prevents any other thread from acquiring that lock until the holder of the lock receives it.
4. Every object has a lock associated with it, and that lock can be acquired and released through the use of synchronized methods and statements. The terms syschronized code describes any code that is inside a synchronized method and statement.
EE3206/EE5805 Java thread-2
EE3206/EE5805 Java programming and Applications
notes on 14.2 using Runnable
from Gosling etc.. 's "The Java Programming Language , 4ed"
1.The work done by a thread is oackaged up in its run() method.
2. You can execute a Runnable object in its own thread by passing it to a thread constructor. If a thread object is constructed with a runnable object, the implementation of Thread.run will invoke the runnable object's run() method.
3. Real classes define complete state and behaviour, where having something execute in a separate thread is only a part of theit functionality.
4. Eg. new thread(this).start();
--While we didn't keep a reference to the thread, when the thread itself was created, it stored a reference to itself in its ThreadGroup.
5. We can place the run() method in part of an anonymous inner class (interface based) that implements Runnable. Eg.
6. Using Runnable objects, you can create very flexible multithreaded designs. Each Runnable becomes a unit of work and each can be passed from one part of the system to another.
7. We can store Runnable objects in a queue and have a pool of worker threads servicing the work requests in the queue-- a very common design used in multithreaded server applications.
notes on 14.2 using Runnable
from Gosling etc.. 's "The Java Programming Language , 4ed"
1.The work done by a thread is oackaged up in its run() method.
2. You can execute a Runnable object in its own thread by passing it to a thread constructor. If a thread object is constructed with a runnable object, the implementation of Thread.run will invoke the runnable object's run() method.
3. Real classes define complete state and behaviour, where having something execute in a separate thread is only a part of theit functionality.
4. Eg. new thread(this).start();
--While we didn't keep a reference to the thread, when the thread itself was created, it stored a reference to itself in its ThreadGroup.
5. We can place the run() method in part of an anonymous inner class (interface based) that implements Runnable. Eg.
...
public PrintServer2()
{
// constructor
Runnable service =
new Runnable() {
public void run() {
for(;;)
realPrint(request.remove() );
}
}; // queer
new Thread(sevice).start();
}
...
6. Using Runnable objects, you can create very flexible multithreaded designs. Each Runnable becomes a unit of work and each can be passed from one part of the system to another.
7. We can store Runnable objects in a queue and have a pool of worker threads servicing the work requests in the queue-- a very common design used in multithreaded server applications.
EE3206/EE5805 Java Threads-1
EE3206/ EE5805 Java Programming and Applications
notes on Threads from "The Java Programming Language, 3rd" p 229-231:
Creating Threads
1. To create a thread of control, you start by crating a Thread object:
Thread student = new Thread();
2. When the thread is ready to run, you invoke its start() method. The start() method spawns a new thread of control based on the data in the Thread object, then returns.
3. The JVM invokes the new thread's run() method, making the thread active. You can invoke start() only ONCE for each thread--invoking it again results in an
IllegalThreadStateException.
4. When a thread's run() method returns, the thread has exited. You can cease running a thread by invoking its interrupt() method.
5. To get a thread that does something, you must either extend Thread to provide a new method or create a Runnable object and pass it to the thread's constructor.
6. You can get the Thread object for the currently running thread by invoking the static method Thread.currentThread.
notes on Threads from "The Java Programming Language, 3rd" p 229-231:
Creating Threads
1. To create a thread of control, you start by crating a Thread object:
Thread student = new Thread();
2. When the thread is ready to run, you invoke its start() method. The start() method spawns a new thread of control based on the data in the Thread object, then returns.
3. The JVM invokes the new thread's run() method, making the thread active. You can invoke start() only ONCE for each thread--invoking it again results in an
IllegalThreadStateException.
4. When a thread's run() method returns, the thread has exited. You can cease running a thread by invoking its interrupt() method.
5. To get a thread that does something, you must either extend Thread to provide a new method or create a Runnable object and pass it to the thread's constructor.
6. You can get the Thread object for the currently running thread by invoking the static method Thread.currentThread.
Abonnieren
Posts (Atom)