Attention avec les Synchronized, des locks peuvent se créer:
http://docs.oracle.com/javase/tutori.../locksync.html
Idem pour les Thread avec Wait...
Je remarque qu'il y a un catch avec un print du stack.
C'est mal géré: si le code juste au dessus du catch plante, il va ramer à cause du catch.
J'ai déjà eu cela dans un programme.
Perso, je préfère mettre mes catch sur toute une procédure/fonction comme cela tout est englobé et il sort en cas d'erreur.
Il y a aussi des log dans des boucles, hai hai...
This Java Tutorial (lien au dessus) can probably help you understand what using synchronized on an object does.
When object.wait() is called it will release the lock held on that object (which happens when you say synchronized(object)), and freeze the thread. The thread then waits until object.notify() or object.notifyAll() is called by a separate thread. Once one of these calls occurs, it will allow any threads that were stopped due to object.wait() to continue. This does not mean that the thread that called object.notify() or object.notifyAll() will freeze and pass control to a waiting thread, it just means these waiting threads are now able to continue, whereas before they were not.
Il ne te manque pas des Notify car tu fais un Wait quand tu appelles Synchronized(object).
Partager