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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:13:06+00:00 2026-05-28T22:13:06+00:00

I was going through a Java tutorial where it was mentioned that actual multithreading

  • 0

I was going through a Java tutorial where it was mentioned that actual multithreading doesn’t happen in a machine having a single processor. It mentioned that OS allots a specified amount of time for the Java process and JVM thread scheduler picks up threads for running one thread at a time for a small amount of time.

I have a laptop which quadcore processor – it is possible to run a multi-threaded program faster programatically by running one thread in each core? The reason why I am asking this question is because the book mentioned that only a true multi processor system can do multiple things at the same time.

  • 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-28T22:13:07+00:00Added an answer on May 28, 2026 at 10:13 pm

    Even a single CPU can do “multiple things at the same time” in a loose sense, but they are not truly in parallel. You can start 100 threads to run on a single core and they will get time slices during which each of them can run a few instructions, thus creating the impression that they are all executing at the same time.

    As I’ve said in another SO post: multithreading on dual core machine?

    The term threads usually covers three abstraction layers:

    1. User threads are threads launched by applications and are mapped N:M to:
    2. Kernel threads, which are threads managed by the operating system, mapped N:M to:
    3. Hardware threads, which are the actual physical resources available.

    Java threads are user threads. The 4 cores in your CPU count as hardware threads. Since the mapping is N:M across the layers, you can see that you can have several user threads mapped to a smaller number of hardware threads.

    Now, having said this, there are generally two classes of thread activities, each with their own quirks:

    1. I/O threads: these threads spend most of their time waiting on read/write operations from a stream and are blocked in the meantime (they are not scheduled for execution until an event occurs to wake them up). There are light on the CPU and a lot of them can run concurrently even on a single core.
    2. Computational threads: these thread do a lot of number crunching and use the CPU to the maximum. Generally starting more than (2x the number of available cores) such threads is going to degrade performance, because the CPU has a limited number of functional units: ALUs, FPUs, etc.

    The second class of threads above lets you really see the benefit or running a multithreaded java program on your quad-core CPU. Here is a simple example of a program that executes squaring of 1.000.000.000 numbers first sequentially and then in parallel using a thread pool with 4 threads:

    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.TimeUnit;
    
    class ThreadTask implements Runnable {
    
        private int total = 0;
    
        public ThreadTask(int total) {
            this.total = total;
        }
    
        @Override
        public void run() {
            int value = 0;
            for(int i = 0; i < total; i++) {
                value = i * i;
            }
        }       
    }
    
    public class Test {
    
        public static void main(String[] args) throws InterruptedException {
    
            int total = 1000000000;
    
            long start = System.currentTimeMillis();
            long value = 0;
            for(int i = 0; i < total; i++) {
                value = i * i;
            }       
            long stop = System.currentTimeMillis();
    
            System.out.println((stop - start) + " ms");
    
            ExecutorService exec = Executors.newFixedThreadPool(4);
            start = System.currentTimeMillis();
            for(int i = 0; i < 4; i++) {
                exec.submit(new ThreadTask(total / 4));
            }
            exec.shutdown();
            exec.awaitTermination(10, TimeUnit.SECONDS);
            stop = System.currentTimeMillis();
    
            System.out.println((stop - start) + " ms");     
        }
    }
    

    Feel free to adjust the value of total if it’s running too fast. Now I’m working on a netbook with Intel Atom, so it not really fast.

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

Sidebar

Related Questions

I am going through the Java EE 6 tutorial and I am trying to
I was going through the document in Java Memory Management and in that I
I am going through Sun's Java tutorial. I am in the lesson about sockets.
Going through a tutorial for android (related to multithreading, loopers and handlers), i came
While Going through the java tutorial on sun site, I see following piece of
I am new to mongodb and as I going through the tutorial for Java
does anyone know the java packages that flickrj is dependent on? I'm going through
I was going through TypeErasure topic at http://download.oracle.com/javase/tutorial/java/generics/erasure.html which says that compiler removes all
I was going through some java code(which uses playframework ) that provides some shopping
All, I'm going through the Friedman & Felleisen book A Little Java, A Few

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.