• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization and Thread

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am using Wicket but I think this is more of a Java question. I am using a List to display the process of a batch job. A thread spawns off and will process the csv file. Each row in the CSV file is a job to process and each finished row will be stored into a BatchLine object which is then added to the List. The problem is for some reason if this page is running and I open a new instance of the Wicket application, it serializes the object and then deserializes it. Well the thread loses focus on the list during this and stops updating the List that is attached to the webPage.. Now I know we cannot serialize a thread, but during the serialization and deserialization process.. how do I keep the List between the webPage class, and thread using it the same upon deserialization? I am also using Collection.Synchronization like so:

List batchLines = Collections.synchronizedList(new CopyOnWriteArrayList<BatchLine>());

I currently pass the object around as parameters in the method, and also into the constructor of the runnable class.

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am pretty sure this is not a standard Java / synchronization issue. I don't know what a BatchLine object is, or what Wicket is, or why it would be serializing and deserializing things behind your back, but it must be Wicket-specific because that is not a Thread or synchronization behavior. Once you serialize and deserialize the List, it is a completely different instance of the List. If you need to use the new instance of the List in the old Thread instance then you will need to inject the List back into the Thread, perhaps using a volatile variable and some key synchornization points where the swap-out can take place. For example, before using the List, the Thread always calls a List getData() method which returns the List. Then whenever a new List instance is created it calls a setData(List) method which stores the List in the shared volatile variable. Of course, that relies on there being some Object which the Thread and the Wicket thingy shares as the same instance (that does not get serialized and deserialized).

A few things to consider:
1) Are you sure the List is serialized and deserialized? How do you know?
2) What does 'launch a new instance of the Wicket application' mean? Is it a new process (if so, then the problem can't be solved in Java, it must be solved with a cross-process resource such as a database).
 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:
A few things to consider:
1) Are you sure the List is serialized and deserialized? How do you know?
2) What does 'launch a new instance of the Wicket application' mean? Is it a new process (if so, then the problem can't be solved in Java, it must be solved with a cross-process resource such as a database).



Hey Steve, thanks for your response.

2) It mean if I have the application running in one tab, and open it under the same session in a new tab.

1) In the documentation it states there is a pageMap class that stores all the current pages for the user in their session. When new tab is opened it basically serializes all the stored pages in the pageMap and then deserializes (Not sure 100% why, but it does).

Wicket has a class (Application class) that allows you to store and share data to all users who access the application. What I was thinking after reading your response is to store my runnable class into a Hashmap or a List of some sort so I can get back in contact with the original runnable object during serialization/deserialization per each user.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So wicket is some sort of Web app framework? Is it server side or client side?
 
Joseph Cho
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea it's been in development since 2005 I believe. It's a nice powerful framework to help separate front end(Html/CSS) from the back end (Java). Kind of like C# and ASP.net, but (In my opinion) much better. It is server side.

You can find out more info here:

http://wicket.apache.org/



P.S. I think the new logic is working, but I am still in the process of re-working the code. Thanks again!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So from my quick look at a Wicket example: it runs on the server, not on the client. The example of a "Wicket application" I saw was implemented as a JEE Filter; this means that "launch a new instance of the Wicket application' is a highly misleading way of saying anything. Whatever you do on the client side, there's only going to be one instance of the "Wicket application".

As for

In the documentation it states there is a pageMap class that stores all the current pages for the user in their session. When new tab is opened it basically serializes all the stored pages in the pageMap and then deserializes



this sounds quite unlikely to me, because it isn't possible from the server side to tell whether a request comes from a new tab. I would like to see the actual documentation which says that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic