Harshana Dias

Ranch Hand
+ Follow
since Jun 11, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Harshana Dias

Harshana Dias wrote:

Ankit Garg wrote:

This code will create 3 objects i.e. "ab", "c" and "abc"...



Based on the earlier explanation its two right? "ab" and "abc"



Well I later read that, "Generally using JDK 1.6 and above the compiler will automatically join strings together using StringBuilder."

Ankit Garg wrote:

This code will create 3 objects i.e. "ab", "c" and "abc"...



Based on the earlier explanation its two right? "ab" and "abc"
I have redis server 2.8.19 and spring boot 1.3.4, spring-data-redis 1.8.0 jars
7 years ago
I have 3 sentinels set up in a redis replication with 1 redis master and 1 redis slave

I populate below in the application.properties file.



I get below exception when application start,



Here is what sentinel 1 server sentinel.conf looks like. Similar exist in other sentinel servers too and it tracks the redis master with mymaster. I can even telnet to redis master from sentinel.

7 years ago

Harshana Dias wrote:Correction:
1.How come it print 457 with thread id 11 as there is a already task for course id 123? I expect 123 456 11.



Sorry. Its because I add a new Task object to ProcessTask instance. Instead I add below and it prints expected 123 456 11.

7 years ago
Correction:
1.How come it print 457 with thread id 11 as there is a already task for course id 123? I expect 123 456 11.
7 years ago

Stephan van Hulst wrote: That means that the same Task instance will be shared between multiple threads, and that's why we need to use a Lock object to synchronize between them, and use signalAll() to wake them all up when the task is finished.



Thank you. I can now understand your implementation.

Just few clarifications

1. I just wrote the main method using Future so that I can generate the behaviour of multiple threads invoke task perform.




And I pass courseId to ProcessTask which implement Callable.  So from the call() of ProcessTask, I call below,

Just before the executor.submit(task::perform), I add below print statement.



But I see below out put,

Gonna submit1
Submitted1
Gonna submit2
Submitted2
processTasks: 123 456 10
processTasks: 123 457 11

How come it print 457 with thread is 11 as there is a already task for course id 123? I expect 123 456 10.

2. How can I decide a number for threadpool?
7 years ago
I mean since Task class is not static, it will not be share between seperate tasks right? Because each course id has its own Task object?
7 years ago

Stephan van Hulst wrote:No. Like I suggested earlier, tasks should stop themselves. They need shared state to determine when to shut down. Here's how it roughly looks:
You need to keep a Map<String, Task> somewhere, and whenever you load the page, you just submit a new callable to your executor service:



Thank you for your answer with code. Surely it helps me to learn about concurrent.lock package, which something I learn for the first time.

I just have few questions for instance about this id you mentioned in computeIfAbsent. I assume its "courseId" in my context of the question.

If so, what ever tasks (threads) hiting for same course id, would not be add to the tasks map right? Only the initially added task for given course id would be there right?

If above assumption is correct, I am wondering, since the Task class also not static, for a particular course, only one Task object will be initiate right?
Then does this locks and  taskDoneCondition.signalAll() is required?


7 years ago

Paul Clapham wrote:
So when one of those FutureTask objects completes, presumably it knows the courseId so it looks in that Map and finds all of the FutureTask<String> objects which are processing that courseId, and then stops them all.



But can only stop those tasks via the ExecutorService shutdown method know?
7 years ago

Paul Clapham wrote:I don't see what that has to do with Stephan's suggestion. After all we already know that your tasks are going to run in separate threads, so what's the objection to having those tasks/threads communicate via a shared object?



I assume you referering to use ExecutorService of concurrent package.

Suppose below is my method which each thread/task enters. I belive executor shoud be a class variable. Under Callable call method, I have to write the logic which checks the common object (in my case redis cache entry). Am I correct please?



But then again I still need to group those tasks to course id because I cant just shut down all tasks in the executor. I can shut down only tasks which process same course.  Based on my above code despite of which course a thread process, all add to the same ExecutorService. Can you provide suggestions to improve it?

I can think of having a map with key as the course id and value as ExecutorService object. So basically, I have multiple ExecutorService per course id's. Does below approach is correct?



7 years ago
I have use spring boot acurator health with spring fox swagger in a spring boot projet. I use below in my Application.java class.


But when I check the swagger ui, I see multiple end points for health with all types of http methods include POST,DELETE, OPTIONS etc. For myservice1 which implement in the REST contoller, it only display the GET method.

This TestMeHealthEndpoint extends AbstractEndpoint and overide invoke method with custom health information.

I only want to see is the GET method for the health route?
7 years ago

Paul Clapham wrote:You didn't like this answer? Why not?



I have to work with threads in order to check a redis entry in time to time (by sleep and wake the thread)
7 years ago