Azure Container Apps is a fully managed serverless container
service that enables you to build and deploy modern,
cloud-native Java applications and microservices at scale. It
offers a simplified developer experience while providing the
flexibility and portability of containers.
Of course, Azure Container Apps has really solid support for our
ecosystem, from a number of build options, managed Java components,
native metrics, dynamic logger, and quite a bit more.
To learn more about Java features on Azure Container Apps, visit
the documentation page.
You can also ask questions and leave feedback on the Azure
Container Apps GitHub page.
Partner – Microsoft – NPI EA (cat= Spring Boot)
Azure Container Apps is a fully managed serverless container
service that enables you to build and deploy modern,
cloud-native Java applications and microservices at scale. It
offers a simplified developer experience while providing the
flexibility and portability of containers.
Of course, Azure Container Apps has really solid support for our
ecosystem, from a number of build options, managed Java components,
native metrics, dynamic logger, and quite a bit more.
To learn more about Java features on Azure Container Apps, you
can get started over on the documentation page.
And, you can also ask questions and leave feedback on the Azure
Container Apps GitHub page.
Partner – Orkes – NPI EA (cat=Spring)
Modern software architecture is often broken. Slow delivery
leads to missed opportunities, innovation is stalled due to
architectural complexities, and engineering resources are
exceedingly expensive.
Orkes is the leading workflow orchestration platform
built to enable teams to transform the way they develop, connect,
and deploy applications, microservices, AI agents, and more.
With Orkes Conductor managed through Orkes Cloud, developers can
focus on building mission critical applications without worrying
about infrastructure maintenance to meet goals and, simply put,
taking new products live faster and reducing total cost of
ownership.
Modern software architecture is often broken. Slow delivery
leads to missed opportunities, innovation is stalled due to
architectural complexities, and engineering resources are
exceedingly expensive.
Orkes is the leading workflow orchestration platform
built to enable teams to transform the way they develop, connect,
and deploy applications, microservices, AI agents, and more.
With Orkes Conductor managed through Orkes Cloud, developers can
focus on building mission critical applications without worrying
about infrastructure maintenance to meet goals and, simply put,
taking new products live faster and reducing total cost of
ownership.
eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
Handling concurrency in an application can be a tricky process
with many potential pitfalls. A solid grasp of the
fundamentals will go a long way to help minimize these issues.
Get started with understanding multi-threaded applications with
our Java Concurrency guide:
Spring 5 added support for reactive programming with the Spring
WebFlux module, which has been improved upon ever since. Get
started with the Reactor project basics and reactive programming
in Spring Boot:
Since its introduction in Java 8, the Stream API has become a
staple of Java development. The basic operations like iterating,
filtering, mapping sequences of elements are deceptively simple to
use.
But these can also be overused and fall into some common
pitfalls.
To get a better understanding on how Streams work and how
to combine them with other language features, check out our guide
to Java Streams:
Yes, Spring Security can be complex, from the more advanced
functionality within the Core to the deep OAuth support in the
framework.
I built the security material as two full courses - Core and
OAuth, to get practical with these more complex scenarios. We
explore when and how to use each feature and code through it on
the backing project.
Traditional keyword-based search methods rely on exact word
matches, often leading to irrelevant results depending on
the user's phrasing.
By comparison, using a vector store allows us to represent the
data as vector embeddings, based on meaningful relationships. We
can then compare the meaning of the user’s query to the stored
content, and retrieve more relevant, context-aware
results.
Explore how to build an intelligent chatbot using MongoDB
Atlas, Langchain4j and Spring Boot:
Accessibility testing is a crucial aspect to ensure that
your application is usable for everyone and meets
accessibility standards that are required in many countries.
By automating these tests, teams can quickly detect
issues related to screen reader compatibility, keyboard
navigation, color contrast, and other aspects that could pose a
barrier to using the software effectively for people with
disabilities.
Learn how to automate accessibility testing with Selenium and
the LambdaTest cloud-based testing platform that lets
developers and testers perform accessibility automation on over
3000+ real environments:
Handling concurrency in an application can be a tricky process
with many potential pitfalls. A solid grasp of the
fundamentals will go a long way to help minimize these issues.
Get started with understanding multi-threaded applications with
our Java Concurrency guide:
Daemon threads in Java are background threads that support other tasks, like system garbage collection, logging, system monitoring, and more. They run with lower priority and the Java Virtual Machine (JVM) terminates them after all user threads finish. Many JVM threads are daemon threads by default.
In this short article, we’ll explore the main uses of daemon threads, and compare them to user threads. Additionally, we’ll demonstrate how to programmatically create, run, and verify if a thread is a daemon thread.
2. Creating Daemon Threads
To create daemon threads, all we need to do is to call setDaemon() of the Thread API. In this example, we’ll use the NewThread class which extends the Thread class:
NewThread daemonThread = new NewThread();
daemonThread.setDaemon(true);
daemonThread.start();
Any thread inherits the daemon status of the thread that created it. Since the main thread is a user thread, any thread created inside the main method is by default a user thread.
The method setDaemon() can only be called after the Thread object has been created and the thread hasn’t been started. An attempt to call setDaemon() while a thread is running throws an IllegalThreadStateException:
@Test(expected = IllegalThreadStateException.class)
public void whenSetDaemonWhileRunning_thenIllegalThreadStateException() {
NewThread daemonThread = new NewThread();
daemonThread.start();
daemonThread.setDaemon(true);
}
Additionally, we can use the isDaemon() method to check if a thread is a daemon thread:
@Test
public void whenCallIsDaemon_thenCorrect() {
NewThread daemonThread = new NewThread();
daemonThread.setDaemon(true);
daemonThread.start();
assertTrue(daemonThread.isDaemon());
NewThread userThread = new NewThread();
userThread.start();
assertFalse(userThread.isDaemon());
}
3. Differences Between Daemon and User Threads
So, we learned that Java offers two types of platform threads: user threads and daemon threads. While user threads are high-priority threads, daemon threads are low-priority threads whose only role is to provide services to user threads.
Let’s highlight other differences between daemon and user threads:
Feature
Daemon Threads
User Threads
Priority
Lower priority, mainly for background services
Higher priority, for main application tasks
JVM Behavior
JVM exits when only daemon threads are running
JVM continues running as long as any user thread is alive
Typical Use Cases
Garbage collection, system monitoring, etc.
Application logic, main program flow
Lifecycle
Automatically terminates when all user threads finish
Needs to be manually terminated
Since daemon threads are meant to serve user threads and are only needed while they are running, they won’t prevent the JVM from exiting once all user threads have finished their execution.
Infinite loops typically exist in daemon threads and won’t cause problems. This is happening because any code, including the finally blocks, won’t be executed once all user threads have finished their execution. As a result,daemon threads aren’t recommended for I/O tasks.
However, there are exceptions to this rule. Poorly designed code in daemon threads can prevent the JVM from exiting. For example, calling Thread.join() on a running daemon thread can block the application’s shutdown.
4. Conclusion
In this quick tutorial, we’ve seen what daemon threads are and what they can be used for in a few practical scenarios. Following that, we compared daemon threads to user threads, focusing on their differences.
The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
Baeldung Pro comes with both absolutely No-Ads as well as
finally with Dark Mode, for a clean learning experience:
Once the early-adopter seats are all used, the price will go
up and stay at $33/year.
Partner – Microsoft – NPI EA (cat = Baeldung)
Azure Container Apps is a fully managed serverless container
service that enables you to build and deploy modern,
cloud-native Java applications and microservices at scale. It
offers a simplified developer experience while providing the
flexibility and portability of containers.
Of course, Azure Container Apps has really solid support for our
ecosystem, from a number of build options, managed Java components,
native metrics, dynamic logger, and quite a bit more.
To learn more about Java features on Azure Container Apps, visit
the documentation page.
You can also ask questions and leave feedback on the Azure
Container Apps GitHub page.
Partner – Microsoft – NPI EA (cat = Spring Boot)
Azure Container Apps is a fully managed serverless container
service that enables you to build and deploy modern,
cloud-native Java applications and microservices at scale. It
offers a simplified developer experience while providing the
flexibility and portability of containers.
Of course, Azure Container Apps has really solid support for our
ecosystem, from a number of build options, managed Java components,
native metrics, dynamic logger, and quite a bit more.
To learn more about Java features on Azure Container Apps, visit
the documentation page.
You can also ask questions and leave feedback on the Azure
Container Apps GitHub page.
Partner – Orkes – NPI EA (cat = Spring)
Modern software architecture is often broken. Slow delivery
leads to missed opportunities, innovation is stalled due to
architectural complexities, and engineering resources are
exceedingly expensive.
Orkes is the leading workflow orchestration platform
built to enable teams to transform the way they develop, connect,
and deploy applications, microservices, AI agents, and more.
With Orkes Conductor managed through Orkes Cloud, developers can
focus on building mission critical applications without worrying
about infrastructure maintenance to meet goals and, simply put,
taking new products live faster and reducing total cost of
ownership.
Modern software architecture is often broken. Slow delivery
leads to missed opportunities, innovation is stalled due to
architectural complexities, and engineering resources are
exceedingly expensive.
Orkes is the leading workflow orchestration platform
built to enable teams to transform the way they develop, connect,
and deploy applications, microservices, AI agents, and more.
With Orkes Conductor managed through Orkes Cloud, developers can
focus on building mission critical applications without worrying
about infrastructure maintenance to meet goals and, simply put,
taking new products live faster and reducing total cost of
ownership.
eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
The Apache HTTP Client is a very robust library, suitable
for both simple and advanced use cases when testing HTTP
endpoints. Check out our guide covering basic request and
response handling, as well as security, cookies, timeouts, and
more:
eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
Handling concurrency in an application can be a tricky process
with many potential pitfalls. A solid grasp of the
fundamentals will go a long way to help minimize these issues.
Get started with understanding multi-threaded applications with
our Java Concurrency guide:
Since its introduction in Java 8, the Stream API has become a
staple of Java development. The basic operations like iterating,
filtering, mapping sequences of elements are deceptively simple to
use.
But these can also be overused and fall into some common
pitfalls.
To get a better understanding on how Streams work and how
to combine them with other language features, check out our guide
to Java Streams:
Traditional keyword-based search methods rely on exact word
matches, often leading to irrelevant results depending on
the user's phrasing.
By comparison, using a vector store allows us to represent the
data as vector embeddings, based on meaningful relationships. We
can then compare the meaning of the user’s query to the stored
content, and retrieve more relevant, context-aware
results.
Explore how to build an intelligent chatbot using MongoDB
Atlas, Langchain4j and Spring Boot:
Handling concurrency in an application can be a tricky process
with many potential pitfalls. A solid grasp of the
fundamentals will go a long way to help minimize these issues.
Get started with understanding multi-threaded applications with
our Java Concurrency guide: