Can Java Objects reinstantiate on their own?
I have a process in my application that uploads a document to my server
via a Servlet and waits for completion, the server then processes the file
using 2 threads, and keeps the Status while it is running.
This is how the Status class looks:
class Status implements Serializable {
private Integer read;
private Integer validated = 0;
private Integer processed = 0;
private Integer failed = 0;
public Status (int read) {
this.read = read;
}
/*
* Getter methods go here.
* No Setter methods.
*/
public void incrementValidated() {
synchronized(validated) { validated++; }
}
public void incrementProcessed() {
synchronized(processed) { processed++; }
}
public void incrementFailed() {
synchronized(failed) { failed++; }
}
}
Now, the server processes the file in this way:
A thread validates the read rows according to DB values, putting in a
queue those that are OK.
A thread waits until it has a batch of items in the queue, and then it
persists the batch of X items.
The Status is updated when the items are OK (incrementValidated), when the
items are persisted (incrementProcessed), and when an item is invalid
(incrementFailed). The Status stored in a ConcurrentHashMap<String,
Status>, where the key is the user's sessionID (because this process can
handle multiple requests).
While the process is running, the client is polling the server via Servlet
too, and all it does is return statusMap.get(sessionId); until the process
is complete.
My problem comes on files that run for too long, for example 5min. When it
is running and polling the server to get the status, sometimes all the
values are set back to 0, and the only value that stays the same is the
read property.
I'm not sure how is that possible, since the object has no setters, so all
I can imagine is that the object is being re-instantiated using the same
value on the constructor, and therefore keeping the same value.
Is that even possible? or am I missing something?
(it looks like the address changes when this happens)
No comments:
Post a Comment