Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!news.albasani.net!.POSTED!not-for-mail From: Sebastian Newsgroups: comp.lang.java.programmer Subject: Re: Concurrent bidirectional one-to-many map? Date: Mon, 09 May 2011 22:57:11 +0200 Organization: albasani.net Lines: 43 Message-ID: References: <08586289-8935-4532-93d0-e8c7dd45cb24@c1g2000yqe.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net g0gANdo5NNvp1KaI4azAFJHCfR2PDZYqzB1Rzas7tBEJNK+zVfHB1tT661TtkHyGkAnyL723yxhGt2GHjJauOg== NNTP-Posting-Date: Mon, 9 May 2011 20:57:11 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="pdvRoCwTyxubEoBxk5jBfrTJHk3/nLHOHCi2cVn8PX8Zi91MAQe7tjmpjjbdPuSieFhvn6/EUxS8pKxtBBrBgWYananXJlwhqpu9BZTQNWOTyU1zs98M8WpzHzq6MV5M"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Cancel-Lock: sha1:2rUod6hSJg/ZrufBAA9fAHkF/Y8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3876 Am 09.05.2011 19:28, schrieb Tom Anderson: > On Mon, 9 May 2011, Robert Klemme wrote: > >> On 8 Mai, 05:51, Tom Anderson wrote: >>>> On 5/7/2011 2:43 AM, Sebastian wrote: >>>> ... >>>>> To give an example, I'm trying to solve a problem like this: >>>>> Associate tasks with workspaces, where a workspace may hold many >>>>> tasks,but a task may be associate with at most one workspace. >>>> ... >> >> This could be solved by standard relationship implementations: Make >> workspace a member of Task and synchronize accesses on Task. Example: >> >> https://gist.github.com/962538 >> >> By using monitors of Task and Workspace we have quite fine granularity >> of locking. > > True! The fastest map is no map at all. > > If the OP can't modify Task or Workspace, perhaps he could consider > writing wrappers which refer to each other, a TaskWithWorkspace, and > WorkspaceWithTasks (perhaps with better names), and passing those around > rather than plain Tasks and Workspaces. > > tom I can't modify Task, or Workspace, and I won't do much "passing around" either, as I'm writing a component that will be called remotely (over RMI). But I suppose I could create a wrapper object for each Item/Workspace on the first call and look them up in maps indexed on the Item/Workspace id. Now I wonder if I just have shifted the problem to these maps? I'll have to brush up on "monitors" and look at the example. As for access patterns, that will depend on worker behavior. If they are well-behaved, they won't competemuch for tasks and finish them quickly, so I'd hope for about as many writes as reads. -- Sebastian