How do you use the Lock interface in Java?
The Lock interface gives explicit control over thread synchronization. See ReentrantLock, tryLock, Condition, fairness and read-write locks, and when synchronized is enough.
2,888 posts about Java: questions with answers, tutorials and articles, newest first.
The Lock interface gives explicit control over thread synchronization. See ReentrantLock, tryLock, Condition, fairness and read-write locks, and when synchronized is enough.
The volatile keyword gives visibility and ordering between threads, not atomic updates. See when a volatile flag is enough and when to use atomics or locks.
A synchronized block lets one thread at a time run a critical section. See how it differs from synchronized methods, how to choose a lock and what to avoid.
Add the synchronized keyword to a method so only one thread runs it at a time on an object. Covers static locks, blocks and alternatives.
The synchronized keyword makes one thread at a time run guarded code and publishes its writes. Compare it with volatile, atomics and ReentrantLock.
Use OuterClass.this in a non-static inner class, pass a reference from a static nested class, and know how anonymous classes and lambdas differ.
A local inner class is a named class declared inside a method. See how it captures effectively final variables, how it differs from lambdas, and local records.
Declare a static nested class in Java, see what it can access, how it differs from an inner class, and when builders and nodes should use it.
The four nested class types in Java with runnable examples, a comparison table, and guidance on inner classes versus lambdas.
final restricts change, finally runs cleanup after try, and finalize() is a deprecated GC hook. See examples, try-with-resources and the Cleaner replacement.
Use static final to declare a constant in Java. See naming rules, how final differs from immutability, and when to choose enums or configuration.
The final keyword prevents reassigning variables, overriding methods and extending classes. Learn each use and why it does not make objects immutable.
Implement Java cloning with Cloneable and clone(), understand shallow and deep copies, and see why copy constructors and records are often better.
Set JMS message priority from 0 to 9 in Spring Boot, enable priority ordering in ActiveMQ, and know when separate queues work better.
Use JmsTransactionManager and transacted listener containers so JMS messages commit or roll back together, and learn why a database write needs an outbox.
ActiveMQ has no shovel element. Use a network connector, an Artemis bridge or a Camel route to forward JMS messages between brokers, with Spring Boot code for both sides.
Federate the Artemis brokers in broker.xml and keep each Spring Boot service connected to its local broker for reliable cross-region messaging.
Set AMQ_SCHEDULED_DELAY with JmsTemplate, enable schedulerSupport on the broker and consume with @JmsListener, with Artemis and fallback options.
JMS has topics rather than fanout exchanges. Learn to broadcast messages in Spring Boot with ActiveMQ topics, durable subscriptions and the RabbitMQ fanout alternative.
JMS has no topic exchange. Learn how Spring Boot publishes and subscribes to JMS topics, including mixed queue and topic setups and durable subscriptions.