Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:03:04+00:00 2026-06-01T11:03:04+00:00

I was attempting to store all the JMS object of the class Message recieved

  • 0

I was attempting to store all the JMS object of the class Message recieved in one minute into a tree map against its precise time as key.After completion of one minute, I wish to serialize the map and return the byte[] to another class. Meanwhile I create a new tree map to store the next set of JMS messages for a minute.

public class StoreMessage {

    private static long start_nanotime = System.nanoTime();
    private static Thread thisThread = Thread.currentThread();
    private static int timeToRun = 60000; // 1 minute
    private static byte[] b = null;
    public static Map<Long, Message> map1 = new TreeMap<Long, Message>();

    public static byte[] store(Message message) {

        new Thread(new Runnable() {

            public void run() {
                try {
                    sleep(timeToRun);
                    thisThread.interrupt();
                    b = serializer.serialize(map1);
                    new TreeMap<Long, Message>();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

        while (!Thread.interrupted()) {
            long precise_time = TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()) + (System.nanoTime()
                    - start_nanotime);
            map1.put(precise_time, message);

        }
        return b;
    }
}

This code is some how not working. Why? It is giving me error of java.lang.OutOfMemoryError: Java heap space Also I noticed that it keeps writing only one message to the map, ie if the messages were “hi”,”good day to you”–these are two jms messages; the StoreMessage class recieves one message at a time..ie it would first receive “hi” and once this message is processed, then it would retrieve the next message. But what i noticed is, for one whole minute, when the thread is not interrupted, it writes only the first message to the map and gives an error. How do i fix these?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:03:05+00:00Added an answer on June 1, 2026 at 11:03 am

    The problem is that your map1 is never actually reset because the assignment is missing.

       public void run() {
                    try {
                        sleep(timeToRun);
                        thisThread.interrupt();
                        b = serializer.serialize(map1);
                        map1 = new TreeMap<Long, Message>();  // Changed this line
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
    

    Of course, you could also simply clear the map:

    map1.clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to send a Point-to-Point JMS message from an oracle database stored
In order to utilize a byte to its fullest potential, I'm attempting to store
I am attempting to store a DevExpress DockPanel in a settings file. Everything appears
I am attempting to store NSMutableDictionaries as a blobs in sqlite, by first converting
I'm attempting to get order data from a Yahoo store. I'm using the docs
I am attempting to use a SQLite database to store emails locally in android.
I'm attempting to get rid of an app's HTML files and store their contents
I'm attempting to select all <script type=text/html> tags in a page. I use <script>
Hey all I am attempting to learn MVC 2 and ASP etc through the
I'm attempting to migrate a Core Data SQLite store in my Mac OS X

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.