download here
Mon Mar 09 00:01:28 HKT 2009
From /weblog/java/concurrency
Even though private List synchList = Collections.synchronizedList(new LinkedList());
is thread safe, serialize sync List is NOT thread safe for sure. The story is, if you only synchronized the collection, and if we try to get the iterator in concurrent access environment, it will throws currencymodificationexception . I personally think this is a bug of having Collections.synchronizedCollection(). For collection is small, may be making defensive copy http://www.javapractices.com/Topic15.cjp is good. Otherwise, in java5, there is concurrency collection. reference: http://jroller.com[..]ntry=collections_synchronizedlist_broken http://jroller.com/page/ctarrington?entry=java_collections_trivia A very good, short discussion about Java5 concurrency support of Map operation, include use of FutureTask and putIfAbsent() method from ConcurrentMap. - http://www.javaspecialists.co.za/archive/newsletter.do?issue=125 Other then lterate through the elements, adding and removing elements can also be problem, this article document a few good cases about that - http://rayfd.wordpress.com[..]en-a-synchronized-class-isnt-threadsafe/ Samples of using Queue.drainTo() - http://binkley.blogspot.com[..]rforming-fixed-amounts-of-work-with.html http://tech.puredanger.com/2009/02/28/java-7-transferqueue/
(google search)
(amazon search)
Thu Oct 02 00:08:39 HKT 2008
From /weblog/java/concurrency
Look like a useful but less known API - http://crazybob.org/2006/07/hard-core-java-threadlocal.html Forward up discussion - http://www.theserverside.com[..]d_id=41473&asrc=EM_NNL_406677&uid=703565 pointing out some problems of using this technique, include similar effect of GLOBLE , possible memory leak Another discussion in higher level - http://blog.objectmentor.com[..]04/thread-local-a-convenient-abomination , Key is "An object is an abstraction of function. A thread is an abstraction of schedule" , you can read further conclusion at http://www.infoq.com/news/2007/09/confusing_uow_with_threads Protential issue of using threadlocal, one is memory leak and the other is it is that local - http://blog.maxant.co.uk/pebble/2008/09/23/1222200780000.html
(google search)
(amazon search)
Tue Aug 05 01:35:59 HKT 2008
From /weblog/java/concurrency
Sometime this is a bit difficult for Chinese to be a good programmer, recently some colleague and me discuss about the behaviour of this class and look like we have difficult understanding A: ConcurrentHashMap support for locking as this is thread-safe B: ConcurrentHashMap is thread safe for read but not for write because there is no lock, we still need to have external lock to keep it thread safe. By the way, I get ConcurrentModificationException from this before. C: ConcurrentHashMap don't support for locking but they still thread safe for all operations, which is how "This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details." mentioned. Too good that we can actually take a look at the source code to see what going on nowadays rather than just guessing - http://www.google.com[..]HashMap&sourceid=opera&ie=utf-8&oe=utf-8 By the way, this constructor is useful for a lot of concurrency access but actually not many developer notice about this - http://java.sun.com[..]rrentHashMap.html#ConcurrentHashMap(int, float, int) Lazy initialization of map values - http://artisans-serverintellect-com.si-eioswww6.com[..]ect-com.si-eioswww6.com/default.asp?W122 HashMap.get() can cause infinite loop - http://lightbody.net[..]5/07/hashmapget_can_cause_an_infini.html Discussing the effect of initCapacity() of HashMap in Java - http://saloon.javaranch.com[..]ltimatebb.cgi?ubb=get_topic&f=1&t=021171
(google search)
(amazon search)
Fri Nov 23 14:07:36 HKT 2007
From /weblog/java/concurrency
Just know that interrupt() call is just setting a flag, it have to be doing IO work (like database call), or in wait() status, before the thread can really be interrupted. http://blogs.sun.com[..]winger?entry=swingworker_stop_that_train Another nice explanation about interrupt, in summary: What should we do when we call code that may cause an InterruptedException? Don't immediately yank out the batteries! Typically there are two answers to that question: 1) Rethrow the InterruptedException from your method. This is usually the easiest and best approach. It is used by the new java.util.concurrent.* package [ http://java.sun.com[..]util/concurrent/Semaphore.html#acquire() ], which explains why we are now constantly coming into contact with this exception. 2) Catch it, set interrupted status, return. If you are running in a loop that calls code which may cause the exception, you should set the status back to being interrupted. For example: while (!Thread.currentThread().isInterrupted()) { // do something try { TimeUnit.SECONDS.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } }Remember the Law of the Sabotaged Doorbell - don't just ignore interruptions, manage them properly! - http://www.javaspecialists.eu/archive/Issue146.html
(google search)
(amazon search)
Thu Aug 02 01:25:51 HKT 2007
From /weblog/java/concurrency
Provides a framework for implementing blocking locks and related synchronizers (semaphores, events, etc) that rely on first-in-first-out (FIFO) wait queues. http://java.sun.com[..]nt/locks/AbstractQueuedSynchronizer.html
(google search)
(amazon search)
Thu May 03 11:43:54 HKT 2007
From /weblog/java/concurrency
An API to get the state of a thread, but someone say it is not reliable http://java.sun.com[..]5.0/docs/api/java/lang/Thread.State.html http://www.nabble.com[..]readed-programs-tf3627394.html#a10128844 Having said that, I have to note that using Thread#getState() is not something you can absolutely rely on as the behavior isn't guaranteed to be the same on all platforms. That is, it can be a useful tool for debugging and test-driving but not ideal for regression (unit) testing. Lasse
(google search)
(amazon search)
Thu Oct 12 15:29:34 HKT 2006
From /weblog/java/concurrency
An example of using Future API which availabe upon 1.5 JVM http://www.alittlemadness.com/?p=32 The other example, make a method timeout and interrupt for sure http://mrfeinberg.com/blog/archives/000016.html
(google search)
(amazon search)
Wed Aug 09 00:59:46 HKT 2006
From /weblog/java/concurrency
There may be more issue rise at concurrency code, althrough I don't know why JVM can't/shouldn't take care all hardward change... http://www.theserverside.com[..]d_id=41602&asrc=EM_NNL_430426&uid=703565
(google search)
(amazon search)
|