No subject
Thu Jun 18 20:39:52 CEST 2009
interesting for the developers working on gvSIG code to
review the Sun documentation about thread synchronization [1]. A bad use
of threads can affect the execution and
performance of the code.
This can affect a code so simple like delaying the creation of an object
until the moment is required instead of
creating it when the containing object is built. For example:
class Example {
Service service = null;
public String getService() {
if( this.service == null ) {
this.seobjetorvice = new Service();
}
return this.service;
}
}
This construction on a multithreaded environment can cause the creation
of two instances of Service, once for every thread.
This can be resolved synchronizing the method:
class Example {
Service service = null;
public synchronized String getService() {
if( this.service == null ) {
this.service = new Service();
}
return this.service;
}
}
Like this simple example, there are more cases where this situation can
happen, and not always the solution is
synchronizing the method. So we think the Sun tutorial is a worth
reading [1].
[1]http://java.sun.com/docs/books/tutorial/essential/concurrency/sync.html
[2]
--
--------------------------------------
Joaquin del Cerro Murciano
Responsable de producción de gvSIG
www.gvsig.org
More information about the Gvsig_internacional
mailing list