Vaibhav Gargs

Ranch Hand
+ Follow
since Sep 08, 2016
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
49
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vaibhav Gargs

We are developing an application in J2EE using Spring, Hibernate, REST. We want to store some data in cache. And, our application will work in clustered envrionment. Is it possible to have common cache in sync on all clusters? How to achieve this?
2 weeks ago
I am learning about Reentrant Lock in Java. I have certain queries related to this:

1. In Reentrant Locks, we can call lock() method multiple times and then need to call unlock() method same number of times. I am unable to understand if I call the lock() method first, I have got the lock, then what is the use of calling lock() method again?

2. In synchroinzed block/methods, we get the lock on object/class depending upon the object. But, in case of Lock API, when we say that we have got the lock, then what is this lock actually?

3. In Reentrant Lock, we have tryLock() method, so, if it gets the lock by calling tryLock(), then it would enter that piece of code, otherwise, will continue with other piece of execution. I am just wondering if I need to continue with other piece of code, then why would I need to the lock at first place itself?

Please share your inputs.

Henry Wong wrote:

Campbell Ritchie wrote:I lways thought it was the other way round.



I thought so too....

Regardless, these two terms seems to be used interchangeably (the regards to threading) these days.

Henry



Hi Henry, Campbell,  concurrent doesn't mean two threads of execution at same point of time? Is my understanding incorrect?

Vaibhav Gargs wrote:Thank you Stephan, Tim.

If we consider the below code snippet, do we have any memory leaks?



Hi Campbell, Tim, If we consider above code snippet, I believe at every iteration of for loop str will point to new String object and hence, all previously created objects will be eligible for garbage collection and therefore, it is not a memory leak. Please suggest.
3 weeks ago
Thank you Stephan.

So, is it correct to say that on a machine with single core cpu, we will have only parallel execution and on machines with multiple cores CPU/multiple CPUs, we can achieve concurrency.
Thank you Stephan, Tim.

If we consider the below code snippet, do we have any memory leaks?

3 weeks ago
Thanks Stephan. But won't push operation overwrite the element at the same location?
3 weeks ago

Tim Moores wrote:

sonai kale wrote:where some objects are not used by the application any more...


... yet the application still retains a reference to them.



Thank you Tim. But I am just wondering how this could be possible.



Considering above piece of code, the list object will be garbage collected once we move out of the method scope. Same would hold true for other variables/references. So, how can an application retain a reference too long?
3 weeks ago
Thanks Stephan. I am bit confused that how can we execute tasks in parallel using one thread?
We have one implementation of SingleThreadPoolExecutor in Java Concurrency package. It actually sequences the steps of execution rather than executing them in parallel. The main use of multithreading approach is to execute the program in parallel. So, I just want to understand the concept and rationale behind SingleThreadPoolExecutor?
I understand that using Runnable, we can't throw exceptions since run method doesn't throw any exceptions. But, using Callable, we can throw exceptions as per call method's signature. I am just thinking that we can have a try catch block within run method and can handle the exceptions there itself. So, what is the explicit need of throwing and handling exceptions using call method?
In Java, we have Garbage Collection in place. So, why do we have Memory Leaks in Java? What are the potential coding issues which could pose memory leaks which needs to be taken care of while writing the code.
3 weeks ago
Thank you Stephan.

So, if we are writing to a concurrenthashmap i.e. using just one segment we acquire the lock on that segment, so, is it possible to perform the read operation simultaneously on that segment or read is blocked while performing any write?
I believe in Optimistic Locking, the row is not locked but checked with some timestamp/version while reading & updating. In Pessimistic Locking, the row is locked until update is made. Though I am not expert but this is what my understanding is about these concepts.
1 month ago
Thank you Stephan.

Please refer the below link:

https://dzone.com/articles/preventing-csrf-java-web-apps


Here, they are setting this as request parameter:



So, anyone can read this hidden parameter and forge the request. Isn't it?
1 month ago