Solved

thread creation

Posted on 2014-02-04
6
334 Views
Last Modified: 2014-02-11
Hi,

I tried below example.

http://www.avajava.com/tutorials/lessons/how-do-i-create-a-thread-in-java.html

When i run the example I  see output in irregular order.

Method 1: extending java.lang.Thread
Method 2: implementing java.lang.Runnable
ThreadSubclass is running
RunnableJob is running

How to fix this issue.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 400 total points
ID: 39834091
What do you mean by irregular order?

Note:  when you start the two threads... there is no guarantee which thread's output will reach the console first.  They should be independent of one another.
0
 
LVL 21

Assisted Solution

by:Amitkumar Panchal
Amitkumar Panchal earned 100 total points
ID: 39837854
Well, I guess the order of last three lines in the output will not be fixed. If you are considering it as an irregular order then it is an expected behaviour in multithreading program.

The reason behind is thread scheduling and it is driven by OS. OS decides which thread to run and put it back to runnable based on no of threads in the memory and its priority.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39843291
The reason behind is thread scheduling and it is driven by OS. OS decides which thread to run and put it back to runnable based on no of threads in the memory and its priority.

Which memory?
OS memory or java memory or laptop hard drive memory. please advise
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 19

Expert Comment

by:Ken Butters
ID: 39843686
Which memory?
OS memory or java memory or laptop hard drive memory. please advise

the handling of threads is done by the JVM. (Java Virtual Machine).

The JVM implementation can be different on different machines.

So the memory will be whatever memory is allocated to the JVM to run the java application.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39851196
So the memory will be whatever memory is allocated to the JVM to run the java application.

How and who allocate memory to JVM. I never remember allocating memory to JVM on my windows laptop. What is the maximum memory i can allocate to JVM.


I see my windowns 7, 64 bit laptop has installed memory(RAM) of 8 GB. How and where to assign memory to jvm. By default how much memory is allocated to JVM. Please advise
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39851256
Is your question about creating threads and the order that output from threads appear... or is it how to set JVM arguments?

Have you had your question answered about threads?

Sounds like you are moving on to another question about JVM parameters.

If your question has not been answered to your satisfaction, then you should ask for a clarification on the answer.

If your original question has been answered, you should allocate the points to the volunteer who was spent time answering your original question fully.  

Please feel free to open additional questions on additional topics as needed.

The order of the output from threads has absolutely NO impact due to the amount of memory allocated to the JVM.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question