You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Wanda Hawk <wa...@yahoo.com> on 2014/07/15 13:23:08 UTC

shared object between threads

How can I declare in spark a shared object by all the threads that does not block execution by locking the entire array (threads are supposed to access different lines from a 2 dimensional array) ?

For example, I would like to declare a 2 dimensional array. Each thread should write on its corresponding line: Thread.currentThread.getId.
By doing this, is the entire 2d array locked by one thread, and therefore other threads must wait to get the lock, or does this approach locks only the corresponding line for each thread ?

Is there another way to do this ?

Thanks,
Wanda

Re: shared object between threads

Posted by Frank Austin Nothaft <fn...@berkeley.edu>.
Hi Wanda,

What exactly is the use case for this? Nominally, you wouldn’t want to do that sort of access, as a single datum can’t be shared across machines when running distributed. Instead, you might want to use an accumulator to manage the aggregation of data in a distributed form.

Regards,

Frank Austin Nothaft
fnothaft@berkeley.edu
fnothaft@eecs.berkeley.edu
202-340-0466

On Jul 15, 2014, at 12:23 PM, Wanda Hawk <wa...@yahoo.com> wrote:

> How can I declare in spark a shared object by all the threads that does not block execution by locking the entire array (threads are supposed to access different lines from a 2 dimensional array) ?
> 
> For example, I would like to declare a 2 dimensional array. Each thread should write on its corresponding line: Thread.currentThread.getId.
> By doing this, is the entire 2d array locked by one thread, and therefore other threads must wait to get the lock, or does this approach locks only the corresponding line for each thread ?
> 
> Is there another way to do this ?
> 
> Thanks,
> Wanda
>