Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2223

Difference between running 2 threads and running 2 classes calling same function

$
0
0

I am exploring blocking read commands on Redis Steram [XREAD and XADD]. Using XREAD we can acquire multi-client blocking read which is released when XADD is executed. This

I am observing the following 2 different behaviour:

Case : 1

public static void main(String[] args){        Runnable t1 = new Runnable(){            public void run(){                function_to_read_block();            }        };        Runnable t2 = new Runnable(){            public void run(){                function_to_read_block();            }        };       new Thread(t1).start();       new Thread(t2).start();}

In this case, the lock acquired is released when 2 XADD commands are executed on redis-cli.

vs

Case : 2

public class ClassA {     public static void main(String[] args){          function_to_read_block()     }}public class ClassB {     public static void main(String[] args){          function_to_read_block()     }}

Running both classes simultaneously, 1 XADD command releases both the read locks at once.[This is the ideal behaviour I was expecting from Case 1 as well]

Can someone explain why is there a difference in these 2 cases? How is running 2 thread different from running 2 separate classes calling the same function simultaneously??

For redis, I am using lettuce library. [Synchronous RedisCluster Connection]


Viewing all articles
Browse latest Browse all 2223

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>