Results 1 to 9 of 9
- 04-04-2012, 12: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); } }I have a class Message and its object message which are passed to the class store message. The "message" objects are string objects passed as command-line arguments. For example "hi" "hello" "good day" -- these are 3 command-line arguments which as passed to this class as Message objects. In this StoreMessage class, i expect it to store all the messages it receives in one minute to a tree map and after a minute has passed, create a new tree map and serialize the previous map and return it to another class which calls for the byte[].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 05:58 AM.
- 04-04-2012, 01: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, 03: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, 05: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, 06: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, 07:32 PM #6
Re: Serializing a tree map every one minute
Where have you posted code that will compile and execute and show the problem?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, 05: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, 07: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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-05-2012, 01:37 PM #9
Similar Threads
-
Please Help Me!!! Last minute test questions...
By justinm231 in forum New To JavaReplies: 1Last Post: 11-10-2011, 06:42 PM -
Counting chars read each minute, infinite loop
By KAS in forum New To JavaReplies: 10Last Post: 03-29-2011, 11:09 AM -
How to export historical data every 1 minute automatically
By franky in forum Advanced JavaReplies: 4Last Post: 05-26-2010, 08:30 PM -
Data Structures(Binary Search Tree to AVL Tree)ASAP pls
By jfAdik in forum Forum LobbyReplies: 0Last Post: 04-04-2010, 07:40 AM -
Serializing
By shashanksworld in forum New To JavaReplies: 7Last Post: 03-29-2010, 04:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks