🔥 Burn Fat Fast. Discover How! 💪

Java Tech News

Logo of telegram channel java_tech_news — Java Tech News J
Logo of telegram channel java_tech_news — Java Tech News
Channel address: @java_tech_news
Categories: Technologies , Apps
Language: English
Subscribers: 558
Description from channel

The channel is dedicated to Java developers who are passionate about learning how the whole Java Platform works. Every post in this channel is a digest of a quality article or reference doc. No bewitched water. Straight to the point.
Dirs: TGDIR

Ratings & Reviews

2.00

3 reviews

Reviews can be left only by registered users. All reviews are moderated by admins.

5 stars

0

4 stars

0

3 stars

1

2 stars

1

1 stars

1


The latest Messages 2

2021-11-29 00:01:05
What is Cache Warmer?
#cloud #cache
Netflix is using EVCache as a tier-0 system (caching layer) for ~14 Pb of data over ~18,000 servers. Caching layer serves multiple use cases from signup, personalization, searching, playback, and more. To limit network impact and shorten the natural warm-up time they have implemented a cache warmer infrastructure.

Cache warming is a process of populating tier-0 systems with cache values before users do that. To let all users experience similarly fast page load cache warmer creates "cold hits" for the spinning cache instance. E.g. in Netflix the first version of their cache warmer takes ~2 hours to prepare 500 mil items and 12 Tb of data for the instance to be fully ready to accept trafic.
netflixtechblog.com/cache-warming-agility-for-a-stateful-service-2d3b1da82642
289 viewsVladislav Chernogorov, edited  21:01
Open / Comment
2021-11-28 00:01:17
Locks 101
#I0I #locks
Locks are one synchronization technique.
• A lock is an abstraction that allows at most one thread to own it at a time
• Every object in Java has a lock
• synchronized keyword creates a critical section by acquiring the lock of an object
• Accesses to a data variable that owns the lock guaranteed to be atomic (uninterrupted by other threads) inside a critical section
• Using a lock tells the processor to flush registers and caches out to shared storage before entering critical section
• Locks are used to implement the monitor pattern — when an object has only mutually exclusive methods guarded by that object's lock
294 viewsVladislav Chernogorov, 21:01
Open / Comment
2021-11-25 12:02:11
What are the bridge methods and how they help to ensure source and binary compatibility?
#bytecode #compiler #jls
When the library changes the method return type from generic to more narrow one (e.g. Number -> Long), users will need to recompile their code or they will get java.lang.NoSuchMethodError. Their JVM will look for a method with a different signature where the method has Number return type (which is no longer exists), not the Long one. To make this work the bytecode has a neat trick called a bridge method. Bridge methods are commonly used among overriding methods of super-types. The runtime has to call an overridden implementation instead of super-type one. However, they also can be used to ensure compatibility in case of evolving a library. For example, org.jboss.bridger:bridger uses ASM bytecode manipulation feature to insert custom bridge method into your code.
https://www.morling.dev/blog/refining-return-type-java-methods-without-breaking-backwards-compatibility/
295 viewsVladislav Chernogorov, 09:02
Open / Comment
2021-11-24 12:00:01
How atomics work in Java?
#atomics #concurrency
Java atomics java.util.concurrent.atomic package has a set of classes that support lock-free thread-safe programming on single variables (values or arrays). Common classes like AtomicInteger or AtomicBoolean are implemented by calling Unsafe or VarHandle methods (depending on the Java version) which are in general just system calls with extra safety steps. The AtomicIntegerArray or AtomicReferenceArray classes further extend atomic operation support to arrays of these types, but they are still have limitations of memory contention.

Atomic operations are very special and provide only limited support. C, C++, Rust, and Swift have relaxed atomics. Relaxed atomics do not create happens-before edges and therefore have no synchronizing effect. Java has VarHandle's “plain” mode. JavaScript has non-atomic accesses to the SharedArrayBuffer (the only shared memory).
281 viewsVladislav Chernogorov, 09:00
Open / Comment
2021-11-23 12:02:24
How to write serverless functions with the latest Java version in AWS?
#aws #serverless #graalvm
Every public cloud has hundreds of SaaS offerings and it's hard to provide the latest runtime for each supported language. What if you want to write an serverless functions with the new Java 17 LTS runtime? As for now, none of the public cloud has provisioned support for that, including AWS, but they do have support for native image creation with GraalVM.

A Lambda deployment package is a .zip file that contains your code and any dependencies. The Lambda execution environment is based on a specific Amazon Linux AMI and kernel version. This year AWS SDK announced that now they have out-of-the-box support for GraalVM Native Image compilation. That means you are free to choose any runtime version you want (starting from Java 8 which GraalVM supports) and it will be even faster than your common bytecode executable.
aws.amazon.com/blogs/developer/graalvm-native-image-support-in-the-aws-sdk-for-java-2-x/
262 viewsVladislav Chernogorov, 09:02
Open / Comment
2021-11-22 00:01:29
What are restrictions applied by sealed classes?
#sealed #classes #jdk17
Sealed classes help developers and compilers by reducing ambiguities in a class hierarchy.
• You can declare class or interface as sealed
• Sealed classes or interfaces permit only specified set of classes/interfaces to be derived (extended) from them.
• Derived classes need to have one of the following modifiers: final, sealed, and non-sealed. Derived interfaces can't be final so they should be declared as sealed or non-sealed.
• non-sealed class or interface opens the declaration for extension (like you write them regularly) but leaving upper hierarchy still sealed.

How can you use it?
The most obvious way is to use them with pattern matching for switch. Just like you did with enum constants now you can create a switch over classes and interfaces. And there will be no default case because sealed permits the definitive number of derivatives.
blogs.oracle.com/javamagazine/post/java-sealed-classes-fight-ambiguity
270 viewsVladislav Chernogorov, 21:01
Open / Comment
2021-11-20 00:02:06
What is the difference between a Process and a Thread?
#threads #processes #os
OS Process
Only one process can be in running state on a single core. Processes communicate either with message passing or shared memory sectors. A context switch is a process of switching the CPU from one process to another, and is a relatively expensive operation. The kernel must manage and schedule processes.
Kernel Threads
Kernel thread, also known as a lightweight process, is a thread that the operation system knows about. Since threads are sharing an address space their context switch is faster than processes'. But still, the kernel must manage and schedule threads.
User-level Threads
This kind of threads is not known to the OS so the scheduling of these threads is done via some library thread-scheduler. Java threads are actually user-level threads, they don't require system calls to create them or context switches to move between them. They can be much faster and lighter than kernel threads.


338 viewsVladislav Chernogorov, edited  21:02
Open / Comment
2021-11-19 12:00:30
How does Failsafe implement circuit breaker pattern?
#failsafe #patterns
Circuit breakers allow you to create systems that fail fast by temporarily disabling execution as a way of preventing system overload. There are two types of circuit breakers:
Count based — tracks recent execution results up to a certain limit.
Time based — tracks any number of execution results that occur within a time period.
Circuit breakers in Failsafe have three states: closed, open and half-open. When a circuit breaker is in the closed state, executions are allowed. In the open state a circuit breaker will fail executions with CircuitBreakerOpenException. After certain duration, the circuit breaker will transition to a half-open state. In the half-opened state trial executions are allowed which determine whether the breaker should be closed or opened again. All requests coming to the application should be handled by a single CircuitBreaker.
https://failsafe.dev/circuit-breaker/
286 viewsVladislav Chernogorov, 09:00
Open / Comment
2021-11-17 00:00:26
When context switching can happen and how it affects performance?
#threads #concurrency
Context switching is a process of OS thread scheduler to decide that a certain piece of code should be executed on a different from the current OS thread. Context switches appear to typically have a cost somewhere between 1 and 10 microseconds. What the kernel needs to do is:
• Change the values of registers, program counter, and stack pointer.
• Memory management information does not need to be changed since the threads share an address space.

Every time we deliberately change a thread's status or attributes (e.g. by sleeping, waiting on an object, changing the thread's priority etc), we will cause a context switch. For different types of context switching there is a different set of kernel operations required. Typically, the cause of excessive context switching comes from contention on shared resources, particularly synchronized locks.
https://www.javamex.com/tutorials/threads/context_switch.shtml
300 viewsVladislav Chernogorov, 21:00
Open / Comment
2021-11-16 12:02:08
What is the difference between wait() and sleep()?
#threads #object
• The fundamental difference is that wait() is non static method of Object and sleep() is a static method of Thread.
• The major difference is that wait() releases the lock while sleep() doesn’t release any lock while waiting.
• wait() is used for inter-thread communication while sleep() is used to introduce a pause on execution, generally.
• wait() should be called from inside synchronise or else we get an IllegalMonitorStateException, while sleep() can be called anywhere.
• To start a thread again from wait(), you have to call notify() or notifyAll() indefinitely. As for sleep(), the thread gets started definitely after a specified time interval.

Similarities
• Both make the current thread go into the Not Runnable state.
• Both are native methods.
https://stackoverflow.com/questions/1036754/difference-between-wait-and-sleep
280 viewsVladislav Chernogorov, 09:02
Open / Comment