Results 1 to 3 of 3
  1. #1
    madnaelo is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default Make a thread Serializable

    This issue is getting too old, please help me.

    I have developed a simple game in java. Everything is fine, the only problem is that when I load a previously save state of the game, It does not load properly. This is due to the Thread class is not serializable.

    Is there any way to save the state of a thread to hard disk? or any workaround?

    Please help

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You cannot "restart" a Thread anyway so serialising it would do you no good. You need to create some "state" object and make that serialisable, then, when reloading, start a thread using this restored state (and you, of course, will have to create the code for determining what to "store" there, and how to interpret it when reloading it).

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    masijade is correct -you can store arrays of item positions, scores, etc... Load that data back in and start a new thread to pick up where the old on left off. You don't just serialize the execution state, you serialize the state of the memory. The execution state should find a stopping point before writing the save, and have the ability to start up from the same arbitrary point. You might need to change your design somewhat to accommodate this.

Similar Threads

  1. Drawing Serializable, how to save/load?
    By warchieflll in forum New To Java
    Replies: 1
    Last Post: 01-03-2011, 05:06 PM
  2. Serializable problem
    By javaPower in forum Advanced Java
    Replies: 3
    Last Post: 11-30-2010, 11:54 AM
  3. marking a field Serializable
    By user1234 in forum Advanced Java
    Replies: 9
    Last Post: 05-18-2010, 12:27 PM
  4. Casting to an List<Serializable>
    By Whatty in forum Advanced Java
    Replies: 5
    Last Post: 10-15-2009, 08:47 PM
  5. Implementing Serializable interface
    By javaplus in forum Advanced Java
    Replies: 4
    Last Post: 12-18-2007, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •