Results 1 to 9 of 9
- 04-04-2012, 01:29 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Serializing a tree map every one minute
Java Code:public class StoreMessage extends Thread { private static int timeToRun = 60000; // 1 minute public static Map <Long,String[]> map1=new TreeMap<Long,String[]>() public static void main(String args[])throws Exception{ long runUntilMillis = System.currentTimeMillis() + timeToRun; while (true) { long now = System.currentTimeMillis(); if (now >= runUntilMillis) { break; } long precise_time=TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis())+(System.nanoTime()-start_nanotime); map1.put(precise_time, args); } returning(); } public static byte[] returning()throws Exception { return serializer.serialize(map1); } }
Java Code:public class serializer { //serializes an object and returns a byte array public static byte[] serialize(Object map) throws IOException { ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(b); o.writeObject(map); return b.toByteArray(); } //de-serialization of the byte array and returns an object public static Object toObject (byte[] bytes) { Object obj = null; try { ByteArrayInputStream bis = new ByteArrayInputStream (bytes); ObjectInputStream ois = new ObjectInputStream (bis); obj = ois.readObject(); } catch (Exception ex) { } return obj; } }
The problem faced here is, the calling class is not receiving the byte[]. Also when i tried printing the map using SOP statement after the while loop, it does not print it and inside the loop when i did the same, i noticed, in my map each of the message is stored more than 5-6 times. Why is the loop spinning this way?Please helpLast edited by kuki; 04-05-2012 at 06:58 AM.
- 04-04-2012, 02:37 PM #2
Re: Serializing a tree map every one minute
Can you make a small simple program that compile, executes and shows the problem?
If you don't understand my response, don't ignore it, ask a question.
- 04-04-2012, 04:52 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Serializing a tree map every one minute
I didn't get you Sir..
- 04-04-2012, 06:19 PM #4
Re: Serializing a tree map every one minute
Create a program that compiles, executes and shows the problem. Post the code for that program here so we can copy it to our computers, compile it, execute it and see the problem.
If you don't understand my response, don't ignore it, ask a question.
- 04-04-2012, 07:59 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Serializing a tree map every one minute
Sir, this is that code...
- 04-04-2012, 08:32 PM #6
Re: Serializing a tree map every one minute
this is that code...
For example where is the main() method?If you don't understand my response, don't ignore it, ask a question.
- 04-05-2012, 06:59 AM #7
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Serializing a tree map every one minute
Done editing Sir..
- 04-05-2012, 08:10 AM #8
Re: Serializing a tree map every one minute
Don't edit your posts after there are responses, except maybe to correct a spelling mistake, as that makes responses lose their relevance and makes the thread difficult to follow.
Post a new response instead.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-05-2012, 02:37 PM #9
Similar Threads
-
Please Help Me!!! Last minute test questions...
By justinm231 in forum New To JavaReplies: 1Last Post: 11-10-2011, 07:42 PM -
Counting chars read each minute, infinite loop
By KAS in forum New To JavaReplies: 10Last Post: 03-29-2011, 12:09 PM -
How to export historical data every 1 minute automatically
By franky in forum Advanced JavaReplies: 4Last Post: 05-26-2010, 09:30 PM -
Data Structures(Binary Search Tree to AVL Tree)ASAP pls
By jfAdik in forum Forum LobbyReplies: 0Last Post: 04-04-2010, 08:40 AM -
Serializing
By shashanksworld in forum New To JavaReplies: 7Last Post: 03-29-2010, 05:47 PM
Bookmarks