Helping ordinary people create extraordinary websites!

Peter Haggar



Author Bio:
 Peter Haggar is a Senior Software Engineer with IBM. He currently works on emerging Java and Internet technology and is the project lead for IBM's real-time Java reference implementation. He has a broad range of programming experience having worked on development tools, class libraries, and operating systems. He is also a frequent technical speaker on Java and other technologies at numerous industry conferences. He received a B.S. in Computer Science from Clarkson University in New York in 1987. He can be reached at haggar@us.ibm.com

Tutorials written by Peter Haggar:

Acquire Multiple Locks in a Fixed, Global Order to Avoid Deadlock
Deadlock occurs when two or more threads are blocked while waiting for each other. For example, the first thread is blocked on the second thread, waiting for a resource that the second thread holds. The second thread does not release this resource until it acquires a resource held by the first thread.
Tuesday, 2nd December 2003

Do Not Reassign the Object Reference of a Locked Object
The synchronized keyword locks objects. Because the object is locked inside of synchronized code, what does that mean to the object and to changes you make to its object reference? Synchronizing on an object locks only the object. You must be careful, however, not to reassign an object reference of a locked object. What happens if you do?
Sunday, 2nd March 2003

Pass-by-value Semantics in Java Applications
A few months ago, developerWorks posted some excerpts from my book, Practical Java, published by Addison-Wesley. I will initially use this column on developerWorks to answer some questions asked by readers and to respond to various comments about the excerpts.
Monday, 24th November 2003

Understanding that Parameters are Passed by Value and not by Reference
A common misconception exists that parameters in Java are passed by reference. They are not. Parameters are passed by value. The misconception arises from the fact that all object variables are object references. This leads to some unexpected results if you do not understand exactly what is happening.
Saturday, 30th August 2003

Use Stack Variables Whenever Possible
When frequently accessing variables, you need to consider from where they are accessed. Is the variable static , on the stack, or an instance variable of a class? Where you store a variable has a significant impact on the performance of code that accesses it.
Thursday, 24th July 2003

Use Synchronized or Volatile when Accessing Shared Variables
When variables are shared between threads, they must always be accessed properly in order to ensure that correct and valid values are manipulated. The JVM is guaranteed to treat reads and writes of data of 32 bits or less as atomic. This might lead some programmers to believe that access to shared variables does not need to be synchronized or the variables declared volatile.
Sunday, 9th March 2003

Use the Finally Keyword to Avoid Resource Leaks
The finally keyword is the best addition to the Java exception handling model over other language's models. The finally construct enables code to execute whether or not an exception occurred. Using finally is good to maintain the internal state of an object and to clean up non-memory resources. Without finally, your code is more convoluted. For example, the following is how you must write code to free non-memory resources without the benefit of finally:
Tuesday, 16th September 2003



GET OUR NEWSLETTERS