Tom
Tom

Reputation: 363

Servlet REST API and thread data exchange

What is the best and simplest way to organize data exchange between servlets and thread? So I have (designing) a thread that manage some process and I have REST servlets that allows to query status and update them also. I am not going to expect too many REST calls, probably one in a second, so I can use synchronized to avoid multi-threading issue.

I suppose that will be able to create a new bean that will run a thread inside it. But how to access it through servlet and have some shared object between them? What's are the problems with this solution?

Upvotes: 0

Views: 161

Answers (1)

rocky
rocky

Reputation: 5004

You have not put many details so its rather hard to answer exactly what you need. First of all - you need to decide if old/good servlets are needed for you, or your functionality can start somewhere in controller with @RequestMapping annotation (if you use spring mvc).

You may want to use session scoped beans to keep any state between REST calls, maybe with mix with ThreadLocal property - please take a look at http://java.dzone.com/articles/painless-introduction-javas-threadlocal-storage thread local explanation.

If still confused -please share more details what exactly is this app going to maintain.

Upvotes: 1

Related Questions