
Originally Posted by
p.g.taboada
Interesting question.
Well, first question is, what about Threadsafety? Where is Spring regarding multithreading: is it "works by accident" or "works by design".
I was working on a blog 'spring and visibility problems' regarding visibility problems in Spring based applications. A lot of beans wont have visibility problems in Java 5 because there is a 'happens before action' between the placement of the bean in a hashmap and the retrieval of a bean in a hashmap: so all changes made by the thread that placed the item in the hashmap are visible in the thread that read the bean from the hashmap.
My question is: is this good design or luck? I make my object threadsafe by design.
If I take one of mine small Spring + Hibernate + [quStruts/JSF/RCP/Whatsoever app - is it going to work on one of those multi-core machines without problems? Always assuming my code isn't doing any magic.
My guess is that visibility problems are going to appear in multicore machines and using Java 5 (the behaviour in Java 1.4 and older is 'undefined'). The new memory model (JSR133) makes perfectly clear what is allowed and what not. So I guess a lot of applications do stuff that is not allowed and this will lead to issues.
example, is this code threadsafe?:
Code:
class MyInt{
private int value;
public MyInt(int value){
this.value = value;
}
public int getValue(){
return value;
}
}
If I have some problem that would be best solved in parallel threads - are there DOs and DON'Ts concerning the framework, are there best practices? Spring is making stuff easier, here too?
Hell yes
I have written multiple applications that use a lot of (custom) multi threading and Spring is a dream to work with. I define what I what, and Spring makes it easy to do.