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 6097659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:04:08+00:00 2026-05-23T13:04:08+00:00

When we start threads in a Java program, is there any way for us

  • 0

When we start threads in a Java program, is there any way for us to assign memory limit to each one of them?

I mean we assign something like this for a new Java process:

/usr/java/default/bin/java -Xms512m -Xmx1024m -jar /opt/abc/MyProcessor/MyProcessor.jar

Is there any way we can do similar thing with Java threads?

Basically, each of my threads is going to do some task, and I wish to put some maximum limit on each one’s memory usage.

  • 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-05-23T13:04:09+00:00Added an answer on May 23, 2026 at 1:04 pm

    Is there any way we can do similar thing with Java threads?

    No. Threads in a process are typically meant to access shared main memory within a process (the JVM in this case).

    Basically, each of my threads is going to do some task, and I wish to put some maximum limit on each one’s memory usage.

    You do either:

    • The easy way. Spawn off new JVM processes where you can specify the heap size on each.
    • The hard way (not recommended by me; this is an option that is available). You could approximate the size of the objects that are created in each thread, and halt further execution of the thread if the size of the objects created by a thread exceeds a certain amount. This will require you to encapsulate the new keyword. In simpler words, all objects will have to be instantiated from factories that will keep tab on the approximate memory usage. Do keep in mind that object sizes on the heap are an approximation; Java does not have a sizeof operator. If you need to keep count of objects on the stack, then it is easy to do so, using the -Xss flag passed to the JVM at startup.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a java application:Why isn't there possible to start two different threads in the
I have a scenario when I start 3..10 threads with ThreadPool. Each thread does
I am having trouble running a Java program with Windows Powershell 2.0. Any help
I am confused on the following: To use threads in a Java program, the
Is there anything wrong with the thread safety of this java code? Threads 1-10
When would you call Java's thread.run() instead of thread.start() ?
Is it possible to get a thread dump of a Java Web Start application?
What's a better way to start a thread, _beginthread , _beginthreadx or CreateThread ?
I'm writing (under linux or windows+cygwin) a java program that needs to run a
I wanted to write a timer in java.which will do the following: when program

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.