There are articles about jvm with byte code, they describe opcodes, symbolic links and linking. But nowhere is the work described in the case of multi-threaded program execution. Do not tell me where to get it?

  • @TagirValeev would like to understand the differences in work between single-threaded and multi-threaded execution. And something to read on this topic - voipp

2 answers 2

If you are interested in writing multi-threaded applications in Java, the best book on this topic is Java Concurrency in Practice (the Russian translation doesn’t seem to exist or I’m looking bad).

If you are interested in the JVM internal device (for example, what system calls achieve multithreading in Windows or Linux, which low-level synchronization primitives are used, in which cases memory barriers are inserted into the generated JIT code), then the best source of knowledge is the virtual machine source code . From the point of view of the JVM, it is strange to raise the question of the differences in work between single-threaded and multi-threaded execution. JVM is always multi-threaded. Even if you are writing a simple console application and do not explicitly create threads, the JVM itself creates separate threads that do JIT compilation, garbage collection, finalization of objects. And, of course, these threads must be synchronized correctly, so multithreading and concurrency always work there. If you write, say, a Swing application, then Swing itself will create threads for you - both AWT-EventQueue and SwingWorkers. If this is a Java-EE server application, there will be even more threads. So, in principle, there is no single-threaded mode.

    If you are interested in how the JVM organizes interaction with memory, which guarantees when accessing data from different streams, what re-ordering happens and happens-before , read JSR-133: Java Memory Model and Thread Specification .

    The specs are quite dry and full of mathematics, so it’s helpful to watch Alexey Shipilev’s report "The Java Memory Model's Pragmatics" in parallel with reading ( slides )

    Ps. And just read the articles about the Java Memory Model , there are a lot of them.

    • thanks, and then every time I try to remember how volatile differs from atomic types, google. And so I understand the basics once and for all. - voipp