Example
protected
void
doGet(
HttpServletRequest
arg0,
HttpServletResponse
arg1) {
Runnable
runner = getRunnable(arg0);
Thread
t =
new
Thread(runner);
t.start();
t.run();
}
private
Runnable
getRunnable(final
HttpServletRequest
arg0) {
return
new
Runnable() {
public
void
run() {
Cookie
[] cookies = arg0.getCookies();
for
(
int
i=
0
; i<cookies.length; i++) {
process(cookies[i]);
}
}
};
}
void
process(
Cookie
cookie) {
// ...
cookie.setMaxAge(
1
);
}
Solution
Instead of using multiple threads, work within a servlet should be done serially. Threads should not be created by J2EE applications, but if threads must be used, they should be pooled.