Synchronized sequential calls to ParameterHandler and URIHandler?

Well, I am having some troubles getting ParameterHandler and URIHandler work synchronized when they are used to produce dynamic material during a “stress” test.
The attached code below is more or less copied from the “book of vaadin” section 11.5.2 Parameter handlers.

The code is a URIHandler to produce dynamic rendered images according to URI parameters sent in the request string.
I had to synchronize the methods “handleParameters” and “handleURI” that are implementing the methods specified by the ParameterHandler and URIHandler interfaces. Otherwise the images produced were very scattered and noisy.
As it is now the images are “clean” but it seem like the calls to the parameter handler and uri handler are not synchronized and that under stress (many calls to the uri) will produce unexpected results. Apparently the calls to parameter handler and uri handler are not made synchronized in a sequential manner.
This means that several calls to the uri can be handled in any order by the parameter handler before the calls reach the uri handler that try to produce the content on the output stream but only uses the parameters from the last call.

Anyone who has any idea on how to make the calls work synchronized in sequence?
12045.java (4.22 KB)
12046.png
12047.txt (12.5 KB)

Hi!

Replace Handlers line
private String text;
with
private Map<Long,String> texts = new HashMap<Long,String>();

Replace set
this.text = textParameterValue;
with
texts.put(Thread.currentThread().getId(), textParameterValue);

And replace get
final String imageText = this.text;
with
final String imageText = this.texts.get(Thread.currentThread().getId());

After that each thread accessing hadleURI method get right text variable.

There might be also other way to handle problem…