Atul More

Ranch Hand
+ Follow
since Dec 26, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Atul More

Thanks Paul for helping me to understand the things and suggesting the approach.

The only thought to create a instance of ThreadPoolExecutor in singleton class is to create the thread pool at the beginning of the whole process and shutDown once the work is over.
So for every call I am avoiding the process of thread creation/destroy instead creating it only once.

That is the reason I created a singleton class and in that I have created ThreadPoolExecutor instance and using it.
5 years ago
Hi Paul,

Let me explain what I am trying to achieve and my questions related to it.

1. I am receiving no. of records at a time (lets say 100000), I want to process them.
2. I am using ThreadPoolExecutor to process them in parallel.
3. I am creating a singleton class (RecordsDistributionExecutor) to create and manage ThreadPoolExecutor. (As creating thread and manage them, is a heavy operation so decide to manage at single point. So creation of thread and all manage easily. That is the thought).
4. Now I have another class which is create an instance of RecordsDistributionExecutor and call the processData() method. (This is not a original code, it is sample code to just get understanding)

5. This RecordsDistributor is called by multiple threads.

Here I am repeating my questions again to get my understanding better:
1. How the processData(r) method works when multiple threads trying to access it. This method is in Singleton class, so can it be access by one thread at a time?
2. As ThreadPoolExecutor is defined as instance variable, how it behave in this singleton class.

Overall if multiple thread trying to access the processData(r) of RecordsDistributionExecutor class. How the behavior will be.

Hope this clear the question and requirement.

Thanks,
Atul
5 years ago
Hi Paul,

Right the execute(Runnable r) is expected. The code is sample not the original which is in the system.

When the RecordsDistributionExecutor instance = RecordsDistributionExecutor.getINstance() return me a single instance.
When I call instnce.processData() method, does it call by one by one as the instance is singleton. Right?

Also, as Stephan suggested related to ThreadPoolExecutor instance at class level and when if instance.processData() is called concurrently then how it behaves?
5 years ago
Hi Stephan,

Thanks for the response.
The expectations are same as you mentioned like I want to understand how it behave.

When I call processData() method, does it call one by one by each thread or concurrently?

Also thanks for useful suggestion to pass the ExecutorService as a constructor parameter whenever required.

Thanks,
Atul
5 years ago
Hi,

I am creating a functionality where I am using executor framework to do some task in parallel way.
For that I am creating a singleton class to create a ThreadPoolExecutor instance.
Here is the code:



My question is:

This RecordsDistributionExecutor is a singleton class to create and use ThreadPoolExecutor instance and only one instance can be created.
1. If the one instance is created then how it behave in multithreading / concurrent environment?
2. Can multiple threads execute the processData() method at a time?

From this I want to understand, how the methods access works in multithreading/concurrent environment for singleton class?


Thanks in advance,
Atul
5 years ago
Thats what I need to understand why it is wrong?
The reason is, I read couple of sites that avoid to use indexes on date or datetome column.
I have to deal with the huge data and it has date column which is very important to me.
So thats the reason I came with this thought and try to understand its pros and cons.
Hi,

I have a question, can we use long or string/varchar2 datatypes to store the date instead of date/datetime itself?
The reason is like date object itself is heavy while sorting, applying index etc i.e. having issues when you need some performance.

So if we store the date in terms of long or in string format like  e.g."yyyyMMddhhmmss" etc then will it help to interns of sort or applying indexing and even helps to cnvert the value into required date format.
Is this assumption is right or wrong?

Thanks,
Atul
Welcome to Ranch and very exited to read the content of the book.
5 years ago
A token for validating each request.
Whenever any request comes to backend, it create a token send it back to UI and for next request the last genereated token send it back to backend. So in response, it send it back new token.
UI is in Javascript and backend in Java, Spring
Hi,

Can somebody help me to understand, how to receive a token from header in Javascript ?
I am almost done withe token creation activity, sending it on header, just want to understand how can I recieve a token on UI side in Javascript?

Thanks,
Atul
Thanks Rob for your quick response.
As you said, I am also thinking related to same line related to locking. If the ConcurrentHashMap is static then how the locking will work is the only thing is in my mind.
Even though the map is used for read the data not even for update or add.
5 years ago
Hi,

Not sure with the question but what happen if I define the ConcurrentHashMap as static?
Does it hamper its performance?

Thanks,
Atul
5 years ago