ben josh

Ranch Hand
+ Follow
since Apr 27, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
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 ben josh

@Rob Spoor
Thanks
Sorry but i didn't understand how to use it for my case can you give short example?
I what to detect the timeout not swallow them ...
Thanks
19 hours ago
Thanks, i still face a problem as i try to implement your solution with small fix but the output is wrong see this :
if you can help here this will be great



currently, if you run this program you will see that the results are connected to the string.

 


what i need that each element will be in its own element e.g :

   
1 day ago
i implemented your solution but the problem is that it is executing
the 2 actions on the string and it concatenate the string and not creating new element in the return list.
what i need is that the new list that is returned will contain the new elements
by the way the toList() not exist anymore in java 8
i had to do it with :



1 day ago
Hello all
i have a simple threaded application which simulates thread timeout, I'm using Thread.sleep(10000)  in the thread to mimic the thread work ,
But i allso want to test this senariue in Junit .
but i can't find away to capture this in junit without adding throw in the method or the worker .



I'm causing this thread to be killed with a small timeout with:



I don't want to add exceptions to all the program hierarchies.

The exception I'm getting:




I guess assertThatThrownBy not going to work here as this exception not thrown
is there any way in jUnit to capture this?
Thanks
2 days ago
Thanks for your detailed answer .
what i did in the end ( in the thread version ) i took you idea of splitting the data to ranges for example :
if i have 5 threads i took the integerList
and did :


This way i divide the integerList to groups by range and sending to the worker thread this way i allso dont need to lock the return list as i know the exsact indexs :


by the way im using :

as it gives me timeout and thread pool out of the box .
2 days ago
Thanks for your great explanation.
I'm still looking into the stream method as an alternative method but from your explanation, its looks really much more simple then using threads.
but what about threads timeouts? what about a thread pool to control how many threads i can execute?
does stream support this?


2 days ago
i try to set a timeout on the thread and expect that the executor to throw exception
and prevent the thread form running that it terminating it but this not the case the timeout working find but the thread do complete to execute. how do i terminate the thread if it passes the timeout? this is my test code :

2 days ago
Thanks for the replay , how would you suggest to divide the integer list  to groups of elements, that will be worked by the actions?  
Although what i did in the end is :
to add new :

and add the elements to this results array





yet not sure if its the right sulotion .. as it works
3 days ago
@Mike Simmons
Thanks
so if i understand you right you suggest that each thread will execute all the actions on each element of the integerList ? right?
also why is the invokeAll is synchronized ? isn't it aproblem ?
4 days ago
what is CompletableFuture().completeAsync ?
also I think you implement it with functional programming , where I can't
i must use threads
4 days ago
what if i set :

it will synchronized on the list

also i can do :



but i guess it the same as all the above-synchronized methods.
but yeah i still have the problem of the list
4 days ago
also the

as it point to the same data every time
4 days ago
its the loop
i replaced it with :


And its working now as this error from what i read invoked when i im editing list that as bean looped
But i don't know if its affecting the thread safeness
Thanks
4 days ago
im getting :



which disappeared after im doing :
private List<Integer> integerList = new Vector<>();
but now i have 2 sync's on the same code what is the right way ?
4 days ago
the code here is a working prototype of a bigger project but just to show the idea.
i have actions i need to do on int a lot of actions on each int.
i decided that all the actions will be stored in a list and all the ints will be stored in the list
each thread will take 1 action and will run on all the list
but keep getting wrong numbers in the result integerList:

Here is the example code :


And here is the result looks like the numbers been accumulated:

4 days ago