• Post Reply Bookmark Topic Watch Topic
  • New Topic

Did You Know???  RSS feed

 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructors cannot be synchronized though the synchronized keywords can be used within constructors
Synchronized modifier is not automatically inherited when a subclass overrides the superclass methods
Locking of an array does not automatically lock its Objects
Locking of an array does not mean that primitive types it holds possess locks.
Lock is released even if the exit occurs due to exception
sleep() does not realease the lock while wait releases the Lock.
Primitive types do not have locks only Objects have locks.
Synchronization in an inner classs is independent of its outer class.
An non-static inner class can lock its containing class with synchronized(OuterClass.this){ }
A new thread created always has the prority equal to the thread that created itunless changed by a programmer using setPriority( int i).
wait, notify and notifyAll are methods of the Object class not of the Thread class
There are two types of threads user threads and daemon threads.
The type of the thread is based on the thread that created it. thus a user thread creates a user thread only while a deamon thread creates a daemon thread only unless the programmer specifically changes the type of the thread
Runnable is an interface with only one abstract method public void run()
A deamon thread can be created by using setDaemon(boolean a).
There is no mechanism to know the thread that created the present thread
There is no mechanism to know who presently owns a lock to the object
The static lock for a class can be accessed inside a instance method synchronized(C.class){ /*body */}
Do you have any Did You Know???

POST IT HERE AND SHARE IT WITH EVERYONE
Regds.
Rahul P. Mahindrakar

 
Michael Finney
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. I learned something too. Did you get most of this knowledge from one book? Just curious.
I wouldn't want to trouble you with citing all your references, but your favorite one would be nice.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
I got most of the above from Concurrent Programming in Java -Second Edition.
 
prasanth chiru
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi rahul,
Tahnkyou much for the good summary. I learned some new points. Keep giving us some more summaries.
Prasanth.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like others to put in some effort too in putting something like this up
 
Viji Bharat
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul:
Could you please explain this?
The static lock for a class can be accessed inside a instance method synchronized(C.class){ /*body */}
Thanks
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
To lock a class (not the instance) you need to enter one of the synchronized methods of the class. Other than this there is another way to do it through a synchronized block.
This is what is being talked about in the lines you have quoted
for example let us say we have a class declared as
public class x{
public static synchronized void dostuff(){
}
public static synchronized void dox(){
}
}
Now the above class can be only locked by entering the two static synchronized methods. Other than this if you want to lock the class this can be done through
synchronized(x.class){
// do some work here
}
Hope this clarifies adequately
 
Viji Bharat
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words, for this class x, is it correct that


synchronized(x.class) is an alternative to the declaration synchronized(this)?


 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"this" refers to an instance while x.class refers to the class itself meaning the static synchronized methods
[This message has been edited by Rahul Mahindrakar (edited October 30, 2000).]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!