Application Startup error: But I got ‘Syntax error in SQL statement’ on application startup: Error: 19:08:45.642 6474 [main] INFO o.h.tool.hbm2ddl.SchemaExport – HHH000476: Executing import script ‘/import.sql’ 19:08:45.643 6475 [main] ERROR o.h.tool.hbm2ddl.SchemaExport – HHH000388: Unsuccessful: CREATE TABLE Person ( 19:08:45.643 6475 [main] ERROR o.h.tool.hbm2ddl.SchemaExport – Syntax error in SQL statement “CREATE TABLE PERSON ( [*]”; expected…
Thread in Java Table Of Contents Getting Thread Name Setting Name to Thread Using Thread Constructor Using Thread.setName() 1. Getting Thread Name By default, the Java compiler sets a default name of each thread while creating, and we can get the thread name by using the Thread.currentThread().getName() method. In the following example, we created a Thread by implementing the Runnable interface and…
Table Of Contents Creating a New Thread By Extending Thread Class By Implementing Runnable Interface Using Lambda Expressions Starting a New Thread Using Thread.start() Using ExecutorService Delayed Execution with ScheduledExecutorService Using CompletableFuture 1. Creating a New Thread In Java, we can create a Thread in the following ways: By extending Thread class By implementing Runnable interface Using Lambda expressions 1.1. By…
Java concurrency is a pretty complex topic and requires a lot of attention while writing application code dealing with multiple threads accessing one/more shared resources at any given time. Java 5, introduced some classes like BlockingQueue and Executors which take away some of the complexity by providing easy to use APIs. Programmers using concurrency classes will feel a lot…
In simple words, concurrency is the ability to run several programs or several parts of a program in parallel. Concurrency enables a program to achieve high performance and throughput by utilizing the untapped capabilities of the underlying operating system and machine hardware. For example, modern computers have several CPUs or several cores within one CPU, the program…
In Java, a synchronized block of code can only be executed by one thread at a time. Also, java supports multiple threads to be executed concurrently. This may cause two or more threads to access the same fields or objects at the same time. Synchronization is the process which keeps all concurrent threads in execution to…
Defining thread safety is surprisingly tricky. A quick Google search turns up numerous “definitions” like these: Thread-safe code is code that will work even if many Threads are executing it simultaneously. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same…
1. Future cancel() API The Future.cancel() method takes one argument of typeboolean boolean cancel(boolean mayInterruptIfRunning); Depending on the value of mayInterruptIfRunning and the status of the task submitted to the executor, the behavior of this method is different: If the task has been completed or has been canceled earlier, or it can’t be cancelled due to any other reason, the…
Executor RejectedExecutionHandler 1. When tasks get rejected Remember, when we finish the execution of an executor, we use the shutdown() method. The executor waits for the completion of tasks that are either running or waiting for their execution. Then, it shuts down the executor. If we send a task to an executor between invoking the shutdown() method and the end…
1. ConcurrentHashMap class The ConcurrentHashMap is very similar to the HashMap class, except that ConcurrentHashMap offers internally maintained concurrency. It means we do not need to have synchronized blocks when accessing its key-value pairs in a multithreaded application. //Initialize ConcurrentHashMap instance ConcurrentHashMap<String, Integer> m = new ConcurrentHashMap<>(); //Print all values stored in ConcurrentHashMap instance for each (Entry<String, Integer> e : m.entrySet()) { system.out.println(e.getKey()+”=”+e.getValue()); } The…