Joshua Kolash edited a comment on Bug JENKINS-17667

I took a look at
https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/tools/InstallerTranslator.java
and see a possible issue.

none of the Map.put or Map.get calls are wrapped in a synchronized block.

According to the java memory model Each Thread can have its own local view of memory that is inconsistent with another Thread.
This is to enable multiple CPUS to have their own caching and not force all reads/writes to be consistent with each other, which would slow things down.

So that if you have

static class A { static int val= 0 };
Thread1: A.a=1;
Thread2: System.out.println(A.a); //Can print out either 0 or 1.

Inorder to have consistency you can use volatiles, so

static class A { static volatile int val= 0 };
Thread1: A.a=1;
Thread2: System.out.println(A.a); //Will print out 1.

A volatile in effect forces a read on main memory instead a per thread cache.

Another way to achieve this effect is to use a synchronized block.

Thread1: synchrnoized(lock) { A.a=1; }
Thread2: synchronized(lock) {System.out.println(A.a); } //Will print out 1.

This is from my understanding of
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Now in your case, your gets and puts are not synchronized, so you can end up with strange behavior. I suggest wrapping your new WeakHashMap() invocations with Collections.synchronizedMap(new WeakHashMap())

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to