Skip to main content

Threading problem

2 replies [Last post]
ted780
Offline
Joined: 2006-01-04
Points: 0

I am having a Threading problem with my Java App. I am running in WSAD 5.1.2 and using Tomcat 4.1 with JRE 1.4.2_08. I have this app Job Groups that users use to assign Job Titles to Job Groups. The system works fine if people log in one by one. But if we have 2 people login at the same time, it fails or returns weird records. List of things I have tried:
1. I have added the 'Synchronized' word to all methods in the app. I realize this may be over kill but had to start somewhere. This was tested and with no change. 2. I coded the App to use one master Form object that is being passed to the Business Objects. This was tested and no change.
3. I tried to utilitize the 'Token' functionality. This used to prohibit people from submitting the same page twice for the same request. This failed as well. I was hoping to customize it to work when sending the object to the database and back to be sure the request had the right one.
4. I then tried to use the 'Thread' class in Struts. I am currently trying to figure how this works. From how I understand it, this assigns a unique number to the request and stores it and you check it when needed to be you in the same thread. Like I said, still trying to figure it out.
5. People are thinking of removing the word 'Static' from the whole App. We some to a certain degree.

So now I am thinking, we can't be the first shop to deal with this issue. Is there anyone out that can help to point me in the right direction? Any help would be greatly appreciated. I have spent way too much time on this already.

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
filip_pas
Offline
Joined: 2003-06-14
Points: 0

You'd really need to provide us with some more information. Stack traces, pieces of sample code etc...

Here's something that worries me though:

[i]I coded the App to use one master Form object that is being passed to the Business Objects[/i]

How could this possibly work? If all your form submissions are handled by a single form object all the data wil inevitable get all mangled up.
Also don't store any user data in any struts action as it will also get mangled up. One action object instance typically serves all requests. If all requests are sequential there's never a problem otherwise troubles arise. You could try have your servlet implement the singlethreadservlet interface. If everything works fine now it's a sign you're mixing data from several users and you'll have to refactor to store the data on the session or rebuild it every request.

Also you should avoid passing any objects belonging to the view to any higher layers like the business layer.
The only exception would be if you use strongly typed forms that don't extend from any presentation framework class.

In the assumption you're using struts check that you reset all the variables in the form object correctly.

Speculations! You need to give some more info!

mike22t
Offline
Joined: 2003-10-03
Points: 0

I probably can't prove it nor accurately explain it but I've had less than predictable results sychronizing in static objects. I improved my results by determining what really needed to be protected and using a singleton instead of a static. Remember to limit the span of sychronization as much as possible in addition to limiting what is sychronized.

Good luck.