Java multicore and multithreading

2010-10-10  来源:本站原创  分类:Java  人气:147 

Recently been discussed in the forum to see multi-core, then,

Associated with multi-core and multithreading so what's it?

I did an experiment,
Implementation environment:
AMD Athlon (tm) 64 X2 Dual Core
Ubuntu i386 / kernel: linux 2.6.32-25
OpenJDK6

1.Main function in the time to start a thread, a CPU 100%

2.Main function in the start when the two threads, 2 CPU 100%

3.Main function in a thread, but start 2 times, and the effect of two similar

Conclusion: The system will automatically deploy CPU, and found that the system will automatically use two CPU utilization in the smaller CPU.
That is, multi-core CPU running multi-threaded program, if the program does not specify when the CPU information, OS CPU core will be responsible for scheduling and management of multi-core CPU does not need to consider OS scheduling. But if they want to balance the load of multi-core CPU, when you create the thread, you can specify the thread's CPU affinity (CPU Affinity), using as linux c api: sched_setaffinity, windows c api: SetProcessAffinityMask, SetThreadAffinityMask function, can interfere with OS of thread scheduling, balance CPU load.

Attachment:

In the core cpu running on the specified thread (c / c + +): http://www.cppblog.com/Khan/archive/2009/12/29/104384.html

JAVA so it?

In the JRockit JVM Management API you can at least Suggest the Process affinity. Not sure if IT is respected on the OS you're running. See http://e-docs.bea.com/jrockit/releases/R27/javadoc/ manapi / Docs / COM / bea / JVM / JVM.html # suggestProcessAffinity (java.util.Collection) for more Information.

JVM jvm = JVMFactory.getJVM ();
List cpus = new ArrayList ();
for (Iterator it = JVMFactory.getJVM (). getProcessAffinity (). iterator (); it.hasNext ();)
{
CPU cpu = (CPU) it.next ();
jvm.suggestProcessAffinity (cpus);
)

You can find JRockit here.
http://www.oracle.com/technology/software/products/jrockit/index.html

===================================
I used taskset on my 4 cpu machine, and by using:
taskset-pc 0 java net.tilialacus.BusyThreads
I gbound all threads to cpu 0. (BusyThreads just runs a few threads with
while (true);

However, if I started the process first, then I have to bind all threads
manually to the CPU. Using ps-eLf I could list all threads (10 or so)
and I could bind each of them separately. I didn't find a way for
taskset to climb the process / thread tree automatically.

相关文章
  • Java multicore and multithreading 2010-10-10

    Recently been discussed in the forum to see multi-core, then, Associated with multi-core and multithreading so what's it? I did an experiment, Implementation environment: AMD Athlon (tm) 64 X2 Dual Core Ubuntu i386 / kernel: linux 2.6.32-25 OpenJDK6

  • Multi-core and multi-threading the difference between 2010-08-31

    Transfer from: http://server.zdnet.com.cn/server/2008/0723/1005241.shtml There is no doubt, " multicore "," multi-threaded "These two words have almost become the processor architecture of the two national school of history as the Warr

  • java.util.concurrent - Multithreading 2010-03-31

    Doug is a selfless man, he knew the sharing of knowledge and sharing is not the same as Apple, Apple will become ever less, and their knowledge and will not give somebody a reduced, more stimulation of knowledge sharing is not the same spark. The con

  • Core java 7 2-1 Multithreading 2010-07-08

    Thread proorityes: highly system dependent xp system level, linux does not poriority. Can not rely on the correctness of priority to complete the process. If there are several high priority of the thread is not blocked, low poriority thread prone to

  • Java thread of thread synchronization 2010-03-29

    Note: wait notify methods are Object synchronization (blocking): is a shared resource to prevent access to data inconsistencies resulting from a model. See more the operating system. In Java, because of multi-threading support, mainly through the syn

  • Simple to use Java threads Introduction 2009-03-04

    Yesterday I read an on Synchronized (thread-safe post), but feel a little strange, in fact, when you understand some basic, you can be completely self-taught Java, but the OO idea is to, through a large number of examples and practical shape. (In fac

  • java threading model 2010-07-03

    Java run-time system implements a thread of execution for the dispatch thread scheduler, is used to determine a moment of which run on a thread in the CPU. Note that thread scheduling is generally done by the operating system, but the java implementa

  • (Reprinted) Java multi-threaded programming Xiangjie 2010-08-04

    Java Detailed multi-threaded programming A : Understanding of multi-threading Multithreading is a mechanism that allows the program to execute multiple instruction streams concurrently , Each instruction stream is called a thread, each independent of

  • Java thread synchronization (synchronized wait notify) 2011-07-28

    Note: wait notify are methods of Object Synchronous (blocking): is a way to prevent access to shared resources, data inconsistencies resulting from a model. See more the operating system. In Java, because of multi-threading support for simultaneous c

  • Garbage collection mechanism 2010-04-14

    In the past year, had their own little concerned about the Java technology, the latest to see, do not let your behind the times! Google queries in a moment, the article on the garbage collection mechanism, integrated a bit, as follows: 1. Tags - Clea

  • Written. Face questions 2010-06-12

    Quote 1. Will the relationship between the Map and Collection? 2. Will the equals and == What is the difference? 3. Please indicate the http in the difference between forward and redirect 4. The basic concept of the thread, the thread of the basic st

  • Frequently Asked Questions Technical Interview 2010-10-10

    Frequently Asked Questions Technical Interview (VIII): Interview Technical Interview This is the final part of an interview: Technical Interview. For computer-related jobs. For this part of the interview, there is no much skill at all, mainly a matte

  • Detailed rules for multi-thread synchronization [I] 2010-11-27

    Transfer from http://earthrelic.blog.sohu.com/157151118.html Familiar with Java's multi-threaded data inconsistencies are generally known to happen there, such as two threads in the operation of the same class variable, while protecting the data with

  • zeroMQ first experience -31. publish / subscribe model Advanced - black box of high-speed subscribers 2011-05-25

    As publish / subscribe model, a common scenario, a large amount of data multicast is necessary. Although the 100k / s is the number of degrees for zeromq commonplace, however, who would not mind it much faster. Model diagram: The core is fully effici

  • Summary of multiple threads 2011-08-01

    Summary of multiple threads 1. Multithreading concepts: Program: is to achieve specific goals or solve specific problems with a computer language command sequence sets. There are files on the drive. Process: an application. Internal data and multiple

  • java multi-threading Xiangjie 2010-03-29

    1: Understanding   multi-threading multi-threading is such a mechanism, which allows the program concurrently execute multiple instruction stream, each instruction stream is called a thread, with each other independent of each other. Thread, also k

  • java multi-threading - OO approach 2010-04-24

    java multithreading legend is an object-oriented, but the api is largely according to OO thinking more "strange". 1, generally we think is a thread blocking another thread, but we in the preparation of multi-threaded programs is to use synchroni

  • java multi-threading - java. util.concurrent.locks.AbstractQueuedSynchronizer resolution (only with multi-thread synchronization example) 2009-10-05

    jdk1.5 and jdk1.6 multi-threading api is somewhat different, this is mainly for the jdk1.5 multi-threaded api's AbstractQueuedSynchronizer explanation. jdk api Many locks are achieved and used within AbstractQueuedSynchronizer achieved. AbstractQueue

  • java multi-threading consumers - producers 2008-11-04

    java multi-threading generally speaking consumers - Producer Model Producer and consumer model, we must ensure the following points: 1 at the same time there can be only one producer in the production 2 the same time, there can only be a consumer spe

  • Java multi-thread synchronization issues to explore (4. Cooperation, collaboration under mutually exclusive - Java multi-threading Collaboration (wait.notify.notifyAll)) 2010-03-25

    Java monitor supports two threads: mutexes and collaboration. We introduced the use of an object in front of the lock and re-entry locks to implement mutual exclusion. This one, we take a look at the thread of collaboration. For example: There is a h