Both the StringBuffer and StringBuilder classes are used to create mutable strings. But StringBuffer are synchronized, which means that only one task is allowed to execute the methods. Consider the following program which appends a “-” mark to a StringBuilder object by 100 threads. import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; public class MutableStringDemo{ static StringBuilder stringBuilder =…… Continue reading What is the difference between StringBuilder and StringBuffer classes.
Author: vubishoo
Java Thread synchronization
To enhance the speed of a program, we use multiple threads to access the same resource at the same time. But, this kind of shared resources can produce unexpected results due to this simultaneous access made by multiple threads. The following example demonstrates the problem. Here, we have a sample bank system that contains 4…… Continue reading Java Thread synchronization
Java Thread pools.
Suppose there is a server software which creates new threads for each and every client requests. When there are a million number of clients are requesting different tasks through the server, the server must create million of threads for them which is a very expensive operation and could limit throughput to cause poor performance. The…… Continue reading Java Thread pools.
Java Thread Methods
Java provides a bunch of methods to manage threads that we create. Few of most important methods are listed down below. MethodUsagegetName() Returns the thread name getPriority()Returns the thread priority sleep()Suspend a thread for a period of timejoin()Wait for a thread to terminateisAlive()Determines if the thread is still running Now let’s see how each of…… Continue reading Java Thread Methods
Multithreaded programming with Java.
A thread is the smallest sequence of instruction executions which can be scheduled by an OS scheduler to run on a CPU. A thread is living inside a process and it is considered as a lightweight process. Threads are the fundamental model of program execution in a Java program, and the Java language and its…… Continue reading Multithreaded programming with Java.
Introduction to Threads and Concurrency.
A thread is simply a sequence of programmed instructions that can be executed independently in CPU. A single process of a program can have several threads, these threads are executed parallelly at the same time within the same process. There are two type of processes based on the number of threads. Single-threaded processes. :- Only…… Continue reading Introduction to Threads and Concurrency.
Process scheduling with Java
As we know a single-core CPU executes its processors one by one at a particular time, but when there are lots of processors in the ready queue, the CPU needs some mechanism to choose one of those processors. In order to do that, we use a logical mechanism for selecting and executing a particular process…… Continue reading Process scheduling with Java
How the CPU works according to LMC(Little Man Computer)
The computer does not take too much time to calculate even a complex calculation, within a few seconds it can solve very large expressions. We all know that the brain of a computer is the CPU(Central Processing Unit), Now, the problem is how the CPU actually solve that much complex expressions so quickly. Actually, the…… Continue reading How the CPU works according to LMC(Little Man Computer)
How to INSERT VALUES INTO table in SQL
A Database is simply a mess of interconnected Data-tables where you store inter-related data in order to make some descriptive information. In a previous post, I discussed how you can create a Data-table in SQL with examples, just make sure you have read that post before reading this. After a Data-table is created in your…… Continue reading How to INSERT VALUES INTO table in SQL
How to create a simple 2 by 2 equation solver in JavaFX with GUI
A powerful way of developing stand-alone applications with awesome interfaces is JavaFX, it uses FXML codes to develop application’s interfaces whereas the back-end of an application is developed by Java. The way of developing JavaFX applications is somewhat different than developing Java Swing applications, in the beginning, you will be a little bit confusing, but…… Continue reading How to create a simple 2 by 2 equation solver in JavaFX with GUI