The course is part of this learning path
In this course, we will learn the concepts of Java EE 7 with a focus on Concurrency Utilities with Threads, Semaphore, Phaser and other methods, and Transactions.
Learning Objectives
- Concurrency Utilities
Intended Audience
- Anyone looking to get Oracle Java Certification
- Those who want to improve Java 7 EE knowledge
- Java developers
Prerequisites
- Have at least 2 years of Java development experience
Hello there. In this lesson, we will talk about concurrency basics in Java. So, let's start. In the computer world, when we talk about concurrency, we talk about a series of tasks that run simultaneously in a computer. This simultaneity can be real if the computer has more than one processor or a multi-core processor or a parent if the computer has only one core processor. All modern operating systems allow the execution of concurrent tasks. You can read your emails while you listen to music and read the news in a web page. We can say that this kind of concurrency is a process-level concurrency but inside a process, we can also have various simultaneous tasks. The concurrent tasks that run inside a process are called threads. Another concept related to concurrency is parallelism. There are different definitions and relations with the concurrency concept. Some authors talk about concurrency when you execute your application with multiple threads in a single-core processor. So simultaneously, you can see when your program execution is apparent. Also, you can talk about parallelism when you execute your application with multiple threads in a multi-core processor or in a computer with more than one processor.
Some other programmers talk about concurrency when the threads of the application are executed without a predefined order. And talk about parallelism when you use various threads to simplify the solution of a problem where all the threads are executed in an ordered way. Since the beginning, the Java platform has offered support for concurrent programming, which was the basis for implementing many of the services offered by Java EE containers. At Java SC5, additional high-level API support for concurrency was provided by the java.util.concurrent package. Prior to Java EE seven, there were no specific APIs that allowed enterprise developers to use concurrency utilities in a safely standard manner. The Java EE web and EJB containers instantiate objects using container-managed thread pools.
Therefore, using Java SC concurrent APIs to instantiate thread objects was strongly discouraged. If a developer creates a new non-managed thread object, the container could not guarantee that other Java EE platform services, for example, transactions and security would be part of this thread. This section presents a number of recipes that show how to perform basic operations with threads using the Java 7 API. You will see how to create and run threads in a Java program, how to control their execution, and how to group some threads to manipulate them as a unit. Benefits of concurrency: The development of multitasking operating systems enable the simultaneous execution of many processes, instances of running programs within a machine, and many threads also called lightweight processes.
They are subsets of a process that can be run concurrently with each other within a process. Due to this progress, it has become possible to run multiple applications at the same time. For example, listening to music and downloading a document while writing a text document. In enterprise applications, concurrency can increase the interactivity of your program by running heavy processing asynchronously in a thread. It can also be used to improve the response time of an application by dividing a big task into smaller units that will be executed simultaneously by many threads. Risks of concurrency:
Although, each thread has its proper stack of execution, it's very common to have multiple threads that share the same resources or depend on each other. In such cases, the absence of good synchronization makes threading behavior unpredictable and can degrade system performance. For example, the lack of coordination of interrelated threads can result in deadlocks and indefinitely interrupt processing. So, that's it for now. Hope to see you in our next lesson. Have a nice day.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.