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

  • Home
  • SEARCH
  • 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 3357060
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:35:18+00:00 2026-05-18T02:35:18+00:00

I am trying to sort an array using multithreading in java and note its

  • 0

I am trying to sort an array using multithreading in java and note its execution time. I am using System.nanoTime() for the same.

Here is a template of the code

start = System.nanoTime();
sort();   // calls different threads to completely sort the array
end = System.nanoTime()

What I want to ask is that the above is in main Thread so will it give me incorrect time results given that I did not put main.sleep() ?? or is it handled by the JVM . Also if I am in need of fast execution is there something that can improve the performance of above code in terms of time execution??

  • 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-18T02:35:19+00:00Added an answer on May 18, 2026 at 2:35 am

    What I want to ask is that the above is in main Thread so will it give me incorrect time results given that I did not put main.sleep() ?? or is it handled by the JVM .

    The System.nanoTime() is supposed to give you the best (most precise) available measure of elapsed time. Note:

    • this is NOT a measure of the CPU time used, and
    • on some versions of Java / OS platforms, System.nanoTime() uses a hardware clock that is not synchronized across different cores, and (apparently) can be rather inaccurate as a result.

    Personally, I’d use System.currentTimeMillis(), and make sure that I benchmarked the sorting of a large array or collection … and did various other things to make sure that my benchmark was valid.

    ( EDIT – If you want to find out how much CPU time was used by each thread, take a look the ThreadMXBean API.)

    Also if I am in need of fast execution is there something that can improve the performance of above code in terms of time execution??

    That is far too general a question to answer, except to say “probably yes” … or “profile it”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a function in C/C++ to sort an array and
I am trying to sort a dict based on its key and return an
I am trying to sort a list using delegates but I am getting a
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I'm looking at the MySQL docs and trying to sort out the distinction between
I'm somewhat new to the ASP.NET MVC architecture and I'm trying to sort out
I am trying to develop an online translation service (sort of a personal challenge)
I am trying to write a JTextPane which supports some sort of coloring: as
I'm trying to order items based on an attribute value: <xsl:apply-templates select=Question> <xsl:sort order=ascending
I'm trying to build a C++ extension for python using swig. I've followed the

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.