This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Depth of Garbage Collection, Thread synchronization  RSS feed

 
aparna shinde
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how much depth of Garbage Collection, Thread synchronization concepts is neccessary for SCJP5. To score maximum on questions including above concepts what more preparation is needed along with its basic info.

These are concepts which I find bit tedious. If anyone can guide Please share the thoughts.
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For garbage collection:

1) Running garbage collector
System.gc();
Runtime.getRuntime().gc();


2) Syntax of finalize() method in class Object and how to override this method.
protected void finalize() throws Throwable { }

see it throws throwable
What default finalize method do?
When finalize() is called?
Who calls finalize()?
How much time JVM can call finalize() on an object?
What could be done in finalize() methods? like: we can resurrect an object again.
What will JVM do if finalize() throw any exception?

3) Practice for code that asks on which line a particular object will be able for garbage collection?
ex: Object o=new Object(); //line1
o=new Object(); //line2
object made at line1 will be garbage collected at line 2.

4) Practice for code that asks how much object will be able to garbage collection after a particular line?
ex: Object o=new Object(); //line1
o=new Object(); //line2
o=new Object();//lin3
o=null;//line4
after line4 there are 3 objects that are able for garbage collection.

[ December 08, 2008: Message edited by: Punit Singh ]
[ December 08, 2008: Message edited by: Punit Singh ]
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For synchronization:
1) method synchronization:

public synchronized void display(){}


2) block synchronization
Object o=new Object();
int i=0;
public void display{
synchronized(o){
i++;
}
}


3) static method synchronization
public synchronized static void display(){}


static int i=0;
public void display{
Class cl = Class.forName("MyClass");
synchronized (cl) {
i++;
}
}


How static method synchronization works?
Static method are class methods, so on which instance they obtain lock as they cannot obtain lock on this?

How to use threads?
How to use wait(), notify() and notifyAll() of Object class?
Look questions for: wait(), notify(), nofityAll() without synchronization.

Where we can use synchronized keyword?
we cannot use synchronized keyword with class, interface and variable.

[ December 08, 2008: Message edited by: Punit Singh ]

[ December 08, 2008: Message edited by: Punit Singh ]
[ December 08, 2008: Message edited by: Punit Singh ]
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Punit Singh:

1) Requesting JVM for garbage collection


One minor correction here, you cannot request JVM to run garbage collection (i.e. it won't happen when you call the method). The method suggest JVM to run garbage collection. Click here for more information. There might be some trick questions about this, be aware.
[ December 08, 2008: Message edited by: Duc Vo ]
 
aparna shinde
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the helpful information .
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember explicit call to GC was a part of 5.0 and has been removed from 6.0. Aparna is giving 5.0 exam so it is of use to her. Those who want to give the 6.0 exam need not to worry about that...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!