Alex Rivera | Logout

In Java, How do I make sure my web application is thread safe?

Asked 2010-02-10T20:08:44.207
14

How do I make sure my java servlets web application is thread safe? What do I need to do in regards to session variables, static variables of a class, or anything else that could be a thread-safety problem?

Edit
Report

1 Answer

1

Wow, that's a loaded question.

To put it simply, you need to ensure that access to any shared data is carefully synchronized. E.g., you may want to synchronize access to a static variable with a mutex or a synchronized function.

Note that you may also need to synchronize at higher levels if you need atomic transactions that modify multiple shared resources at the same time.

Designing a concurrent application is not simple, and there is no magic bullet (unfortunately). I highly recommend the book "Java Concurrency in Practice" for more information on writing safe concurrent code.

answered 2010-02-10T20:13:18.887

Your Answer