Help with concurrency design

I have a situation similar to the following code where m_array and m_link must be guaranteed to be synchronized. Init will get called by different threads so what is the best way to avoid the deadlock?
public class Foo
private final ReentrantLock m_lock = new ReentrantLock();
private final ArrayList<Integer> m_array = new ArrayList<Integer>();
private final LinkedList<Integer> m_list = new LinkedList<Integer>();
private final int m_id = 1;
public void init( final Statement statement, final Foo foo )
m_lock.lock();
try
foo.m_lock();
try
m_array.add( foo.m_id );
m_list.add( foo.m_id );
foo.m_array.add( m_id );
foo.m_list.add( m_id );
finally
foo.m_lock.unlock();
finally
m_lock.unlock();
Edited by: 806320 on Jan 27, 2011 6:18 AM

806320 wrote:
@YoungWinston -As I mentioned, m_array and m_list must be guaranteed to be in sync. Regardless, Synchronize would not help in anyway with this example, the deadlock occurs no matter which lock mechanism you use.What about this?
public class ListManager<T>
   private final List<List<T>> lists;
   public ListManager(List<T>... lists) {
      this.lists = new ArrayList<List<T>>(lists.length);
      for(List<T> list : lists) {
         this.lists.add(list);
   public synchronized boolean add(T value) {
      for (List<T> list : this.lists) {
         list.add(value);
      return true;
   ... other update methods implemented similarly.
}You'd probably want to make sure that the supplied lists are empty, and if you want to be sure that they can't be updated outside the class you'll also have to clone them; but I suspect that's how I'd go about it.
Unless I'm missing something from your original post, I think it does the trick.
With anyone using JDK 1.5+ is there ever a reason to use Synchronize?Absolutely. In fact, I think I'd have to look pretty hard for situations in which I wouldn't use it.
Winston

Similar Messages

  • Need help with security design!

    Hi,
    I haven't worked with security design very much. Currently I'm about to develop an application to my father which should implement some sort of security.
    One of the reasons for this application besides making my father happy is educating myself.
    The application is an online image album.
    The security could be divided in role-based security and instance level security.
    Role-based (NO PROBLEM):
    A user cannot delete another user, an administrator can delete users.
    Instance-level (DON'T KNOW HOW):
    A user can load other users image albums if he/her is allowed/granted to view the album and its images. Note that the user could be granted to view the album, but not all of its images.
    My problem is how I should design the "instance-level" security? Should I keep a ACL (Access Control List) with each instance of album and image?
    This seems to be a common functionality to add view/load/read/write permissions to an instance in runtime to let a certain user to operate on an asset?
    Have searched the Internet but haven't found any nice framework to help me.
    Could anyone with some experience please help me out?!
    Kind regards, Andreas

    Hi,
    I ran into the same problem. Could you resolve it?
    please give me your feedback.

  • Need help with class design

    I want to design and use one or more classes for a particular project I am working on.
    I need some advice hopefully from someone who has experience in this area. Basically,
    for this particular problem I have two database tables. I want the first class to
    represent the first database table and the second class to represent the second
    database table. An object of the first class will be created first, and then if certain
    criteria are met then an object of the second class will be created.
    Question:
    Should I use classical inheritance and let the first class inherit from the second class?
    Or should I use the containment delegation model and embed an object of the second
    class in the first class?
    ----Tables------
    For example, my first table ET_UserData looks something like this:
    ET_UserData
    (PK)UserName
    Password
    FirstName
    LastName
    My second table ET_DetailedUserData looks like this
    ET_DetailedUserData
    (FK)UserName
    WorkAddress
    WorkPhoneNumber
    CityWhereEmployed
    SocialSecurityNumber
    City
    State
    StreetAdress
    PrimaryTelephoneNumber
    AlternatePhoneNumber
    HasRegistered
    RegistrationDate
    RegistrationTime
    CreditCardNumber
    NameOfPrimaryContact
    DateOfBirth
    Weight
    EyeColor
    Height
    Member
    Here is are some pseudo classes for the two classes.
    Class UserData
    string UserName
    string FirstName
    string LastName
    Class DetailedUserData /* For a classical approach, sub class off of class UserData */
    /* UserData ThisUser --> Containment delegation model */
    string (FK)UserName
    string WorkAddress
    string WorkPhoneNumber
    string CityWhereEmployed
    string SocialSecurityNumber
    string City
    string State
    string StreetAdress
    Int PrimaryTelephoneNumber
    Int AlternatePhoneNumber
    Bool HasRegistered
    Int RegistrationDate
    Int RegistrationTime
    Int CreditCardNumber
    String NameOfPrimaryContact
    Int DateOfBirth
    Int Weight
    Int EyeColor
    Int Height
    bool Member
    }

    Thank you for your help. If you can continue to help me I would appreciate it.
    I and another developer did the database design. Pretty solid design. Plus we have all of the requirements
    which are very good too.
    Originally I wanted just one table to contain all of the data associated with a user. Instead of ET_UserData and ET_Detailed user data I wanted just one table. But I decided to break this table up into the two tables for the following reason.
    1.) This is a web application where each user logs into a web form. At a minimum, in order to use the website the session associated with each user needs the UserName, Password, First and last name.
    This is the data in the first table.
    If they choose to do more specialized functions on this website, then they will need all of the information (Attributes) that are located in the second table. In general 40% of the time all users will need information located in the second table.
    My reasoning for breaking the table into two seperate tables is that I wanted to minimize the amount of data involved in a result set, created from the sql query. The math tells me that 60% of the time most of the data in the result set will not be used.
    2.) If I create one class to represent all of the data/attributes in both tables, then my reasoning is that their will be alot of overhead in the single class because 60% of the time, a majority of the attributes are not needed and used.
    I would deeply appreciate your help with this. You seem to have great insight and advice. Please help me as I increase the duke dollars Sir.

  • Help with a design, using Java Persistence

    I'm having a design issue, and I hope that someone can help.
    I have a table called Item, and it essentially acts as a header table for a group of attributes for that item.
    TABLE Item
    .....id....................long
    .....itemName.........varchar
    .....StartDate........datetime
    .....StopDate........datetime
    If I can, I'd like to design a model that will allow for a dynamic number of attributes for any given ITEM.
    I initially thought that it would be convenient to design the Attributes table like such:
    TABLE Attribute
    .....id....................long
    .....itemID.............long (references Item.id)
    .....attributeName....varchar
    .....value...............?
    .....StartDate.........datetime
    .....StopDate.........datetime
    My problem is the VALUE column. Attributes can be any given type, so this won't work if I want to enforce a data type.
    I don't know where to go from here. I can create a table to include all attributes, but each attribute needs to have a date range.
    Additionally, the history of the attributes must be retained; so, if I succeeded any given Attribute I would need to duplicate the
    entire row (thus, all the other data that didn't change).
    One thought was to create an Attribute table for each of the most common types, but that seems like a really bad idea:
    TABLE AttributeLong
    TABLE AttributeDateTime
    TABLE AttributeVarchar
    etc, etc ...
    I should note that I'm using Java Persistence.

    I agree with you 100%. Here is something I'm trying to get a grip on: there are a finite number of attributes per group, but the number of attribute groups can grow (maybe 20 sets max - but I just don't know yet).
    I would need one table (Entity) for each set of attributes.
    So, for instance, let's say I have:
    Item1 is of kind KIND1 that has an attribute set of SET1
    (ie, tables ITEM and SET1)
    Item2 is of kind KIND2 that has an attribute set of SET2
    (ie, tables ITEM and SET2)
    I'd like to have my Item entity class set up like such:
    myItem.getAttributeSet
    instead of:
    myItem.getAttributeSet1
    myItem.getAttributeSet2
    Since at given time I can extend my application (and add new entity classes to support a new table for SET3), I wanted to avoid changing Item. I can have getAttributeSet return an interface and then cast it, but that still requires changing Item to account for the new entities. Thus, I can't just drop in new "packages."
    I want a flexible and extensible system., but maybe I'm over thinking/engineering this.

  • Help with a design

    Hello,
    I am attempting to replicate a design of a popular Bill Murray T-shirt and need help.
    On the left is the design that I want to have and on the right is my design
    They are close but the one on the right is too cartoonish, the edges are not as crisp and the coloring is not consistent.
    Here are the steps I took:
    -Copied new layer
    -Unlocked Background
    -Image->Adjustments->Black&White
    -Copied Layer->Pasterize->level 3
    -Copied New layer
    -Filter->Artistic->Cutout
    -Levels->8 Simplicity->0 Fidelity->3
    -Image->Brightness/Contrast
    It's not quite what I am looking for, PLEASE HELP!
    Thanks!

    A couple of comments - and these are just my thoughts -
    Part of the reason the image on the left looks as it does is the black background as opposed to the white one on the right. Changing that would probably give a whole different feel to the image to start with.
    If you want to "darken up" and sharpen parts of the image you could try putting a copy of the original layer (I do mean the original - not the gray scale one you have created) above the grayscale layer. Choosing Adjustments / threshold to create a very starkly contrasted image. Then use a combination of opacity level on that layer to reveal the gray image. Alternatively place an inverted mask on the layer (hiding the new B&W layer) and then, using a white brush with opacity of 30% or less to gradually darken the areas of the image that you feel need it.
    As I said - just my suggestion, I am sure other people will have different suggestions.
    Cheers
    John

  • Newbie help with cache design/custom filter

    Hello,
    I'm very new to Coherence, so you'll have to forgive me if these are easy questions. I have an application that contains 1.5 million products. Each product has a map of prices for our client list. So internally, each product object I'm caching contains a pricelist map with up to 100 entries (clients):
    private String productId ;
    private String productName ;
    private Map<String, Integer> priceList; //where the String is the client id and the Integer is the price for that clientHere's my question(s):
    1. Is there any type of query that would return the product info and just the price for the 1 client (there really is no need to send all 100 of them for the individual quries)? How could this be done efficiently?
    2. I need to sort by price. To do so, I've created a filter on the product keys, and a comparator that contains the client ID. This works fine, but it seems to take a long time to sort based on price using the comparator. Is there any other method of sorting that might be more efficient on the Coherence side of things? Sorting by product name is also a bit slow - is there a way to speed that up? The product name is the same for all clients, and thus is a simple string in the object being cached.
    3. Indexing: Is there any way to index the internal Map of the price list? And would that help in performance?
    Since this is a new implementation, the object design for the cache is open for change as well - if there are other structures that would enhance the performance. Any help would be most appreciated!
    Sincerely,
    Chris

    There are actually techniques you could use to keep all the information about an article in the same object. This may be attractive in particular if the information is rarely updated (frequently updating a large object is costly and, unless every attribute changes with every update, breaking up the object graph making some of the objects into separate cache items is then preferable).
    With the later Coherence releases there are for instance PofExtractor that allow you to extract selected parts of an object without de-serializing the whole object. You could probably use this to only extract the "price list"for a product. Combine this with a custom aggregator (that aggregates over all products a customer want to get a quote on) that could extract just that customers price from the "price list" and you would have a quite efficient solution...
    As for indexes you COULD put the price list and other info from the large object in indexes but be aware that Coherence indexes are always stored on heap (other data can nowadays be stored off-heap) and also occupy a lot of space (Coherence always creates both index and reverse index and since Java objects are used to implement them there is quite a lot of overhead)... I would first look into either a 3NF-like solution with mainly primary indexes or a single cacnhe solution using PofExtractors etc...
    /Magnus

  • Help with CSS Designer?

    I am having a lot of trouble with the left side of CSS Designer. Sorry to sound like such a kvetch!
    To take a simple example - From the Welcome screen I create a fuid grid layout and name my style sheet mystyles.css. When the document window/program opens I am seeing boilerplate.css in bold and only two selectors down below - "html, button, input, select, textarea" and "html". Why only two since the boilerplate has a huge complement of selectors?
    Next question (more important) - when I click on mystyles.css a list of 16 selectors pops up, although the only one I was expecting to see was the selector for "grid container"! Why does this happen? Why doesn't Dreamweaver let me create my own selectors as I build the site? I have read that mystyles.css should contain only those style rules which I have inserted into the head of my code. Is that not true?
    In general I feel that Adobe relies too much on robotic tutorials without explaining the underlying architecture. When the beginning uses starts out on his/her own, it is easy to get confused.
    Please help!
    Kevin from Cambridge

    Please let me know if you are willing to continue with this.
    That's why I'm here!
    The CSS in each of those stylesheets provides the "boilerplate" layout for your fluid grid pages. Without that CSS, you would have no "fluid" and no "grid". That's why both of them contain pre-defined rules, many of which correspond to the ID's already assigned to the HTML (or the tag(s)) that is/are written on the page when it is first opened.
    The contents of the @media pane are determined by the selections you made for the various widths and gutters in the New Page dialog that opened when you selected the Fluid Grid Layout option. You can adjust these as needed once they are written during this process.
    So what are your further questions?

  • Need Help With Spreadsheet Design

    Hi,
    I write about diabetes on various Internet Forums and am currently involved in testing various blood glucose meters to determine the accuracy of the different makes/models. I am trying to design a spreadsheet in Appleworks to help me evaluate the meters but have very little experience with spreadsheets so am finding it tough going.
    In comparing the various blood glucose values delivered by the meters I am trying to come up with a way to automatically compare 2 readings and then display how much a particular reading is above or below another percentage wise. The difficulty is that a particular meter might sometimes display a value higher than another one time, and lower than another the next time so I'm not sure how to design the speadsheet to automatically calculate the percentages.
    For instance in sample one Meter A reads 115mg/dl and Meter B reads 87 mg/dl so by dividing the 115 into 87 I can determine that Meter A is reading 24% higher than Meter B. But then in sample two Meter A reads 89 mg/dl while Meter B reads 121 mg/dl so in this case Meter B is reading 26% higher than Meter A.
    Is there a way to structure the spreadsheet so that it can compare the two readings and then based upon which one is higher divide the result into the lower one can come up with a percentage?
    Thanks!
    Winston

    Hi Winston,
    Leaving aside any discussion of the actual test design, here's a rundown of how to make the spreadsheet do (most of) what you want it to do.
    What I want the spreadsheet to do is to accept the data from meter 1 and meter 2 in side by side columns of cells. I next want the spreadsheet to compare the 2 bG values obtained from the same blood sample with these meters to one another and then divide the smaller value by the larger value to determine the amount in percent that one meter is higher or lower than the other.
    This division (r/R) compares the smaller value (r) to the larger (R) and reports the result as a fraction.
    eg. 75/100 = 0.75 The smaller reading is 75% of the larger reading, or the smaller reading is 25% lower than the higher reading.
    But that does not mean the higher reading is 25% higher than the lower. That percentage is given by comparing the larger reading to the smaller (R/r). For the same pair of readings:
    100/75 = 1.33.. The larger reading is 33% higher than the smaller.
    As the percentages will be listed in columns labeled "Meter x higher", the R/r division is the appropriate one.
    This is comparison is complicated by the fact that meter 1 will sometimes return the higher of the two readings, and at other times meter 2 will be higher. Thus it's not a simple matter of asking the spreadsheet to divide the result of meter 1 by the result of meter 2 each and every time or vice versa.
    Next on the agenda I want the spreadsheet to put the result obtained by the above calculation in one or the other of two additional columns of cells. In other words the spreadsheet will compare the value of meter 1 to meter 2, divide the smaller value by the larger value to determine percentage, and finally place the result obtained in one of two additional columns of cells. One of these additional columns of cells would be labeled Meter 1 Higher and the other would be labeled Meter 2 higher.
    All of the formulas given previously will make a comparison.
    Niel's and Barry's report the percentage by which the higher reading is higher than the lower.
    Brie's and Terry's report the percentage by which the lower reading is lower than the higher.
    All put the results into the same cell (column) without regard to which reading is highest. (Barry's set includes labels to identify the higher meter.)
    Here's mine again, with revisions to place the results into separate columns:
    Labels in Row 2: C2: Meter A, D2: Meter B, E2: A Higher, F2: B Higher
    Tests results in Row 3, Meter A in C3, Meter B in D3
    Comparison results in E3 and F3
    E3: =IF(C3<D3,"",C3/D3-1) Set the Number Format of this cell to percent.
    F3: =IF(D3<C3,"",D3/C3-1) "
    Note: the IF() statement suppresses the result in the column reporting "is higher" results for the meter with the ;ower reading. Written as above, the formulas will report in both columns where both meters show identical readings.
    Note2: As written, the formulas will return a #DIV/0! error if no results have been entered on that line. The version below suppresses any results until readings have been entered in column D.
    E3: =IF(D3,IF(C3<D3,"",C3/D3-1),"") Set the Number Format of this cell to percent.
    F3: =IF(D3,IF(D3<C3,"",D3/C3-1),"") "
    Roughly 1,000 tests will be performed over a several month timespan and all the meter readings referred to above will each be compared by the spreadsheet.
    The default size of an AppleWorks spreadsheet is 40 columns by 500 rows. Go Format > Document... to increase the number of rows to 1050 to allow room for 'roughly 1000 tests.'
    For 1000 tests, fill the formulas above down through rows 3..1002 (aasumed in examples below).
    Next I want the spreadsheet to examine all the cells in which meter 1 returned the higher result and perform the following calculations:
    lowest percentage over meter 2 obtained
    highest percentage " "
    The second is easy: =MAX(E3..E1002)
    Place the formula where you want this result reported.
    The first runs into a problem: empty cells, or those with non numeric data are evaluated numerically as "0" by the MIN() function. There is a workaround.
    Use an empty column to the right of the active part of the spreadsheet. (I've arbitrarily chosen column M)
    M3: =IF(E3>0,E3,1000)
    Fill down M3..M1002
    This copies all greater than zero values into column M, and inserts a value of 1000 wherever the value in column E is 0.
    The minimum value in this column (which is also the non-zero minimum of column E) is given by:
    =MIN(M3..M1002)
    Place the formula where you want this result reported.
    number of identical readings obtained
    I'm assuming you mean 'identical differences' in terms of percent higher.
    There are a couple of difficulties here:
    1. AppleWorks does not include a MODE() function which would extract the number appearing with the greatest frequency.
    2. What constitutes "identical" depends on the (mathematical) precision of the results. AppleWorks can display results to 11 significant places (eg. 12.345678901), and actually does the calculations to a few more places than that. Given that precision, many results that are not significantly different willl not be identified as "identical."
    Probably doable, but more detail needed before jumping in.
    average percentage " "
    average deviation
    Not sure what you're asking with these. Can you elaborate?
    Regards
    Barry

  • Need some help with this Design.  Not sure if it can be done.

    I am a full time RVer. I have a complex system installed in my RV. I am trying to share a wireless or use my AE to feed internet to the devices in my rack and allow my Apple TV to connect to my MBP over gigabit for streaming reasons.
    Is there a way to share my internet to the AE so that it will feed the 3 ports? Can I somehow connect to a hotspot and share that internet connection to the other devices on my network wired and wireless?? I am mainly concerned with getting internet to the ATV while connected to it via ethernet for the gigabit connection.
    It seems that I can connect the AE to a hotspot or WAP, but then I loose the ability to turn bridged mode off so that it will hand out DHCP ip addresses to the ethernet devices. I cannot extend any network unless the hotspot is using an apple device for its WAP. This is what apple told me when I was trying to extend my Linksys WAP4400N.
    Any ideas or advice here would be great. I am just stuck for a solution to what I want to accomplish.
    Thanks

    One possible solution....(if I understand correctly what you're trying to accomplish with what you have to work with) I'm assuming that the Linksys has no internet connection in the RV and isn't really needed in my idea below.....or do you have a satellite connection (or some other internet source besides a public wireless network?
    You could have your MBP join the wireless network, set up internet sharing (see OS X help) and share from airport to ethernet, connect an ethernet cable from MBP to WAN port on the Extreme, set the Extreme's connection sharing to "share a public IP", ignore the double NAT error (or you may be able to bridge it, I can't remember if the MBP will hand out several IPs but I think it will), and plug your Apple TV into a LAN port on the Extreme. Come to think about it, you really don't even need the Extreme unless you need other clients to connect, just plug the Apple TV into the MBP.
    hope it helps

  • Might Be OT - Need Help With DW Design

    I am in the midst of transferring Access reports to Oracle. A lot of these reports display percentage data. What is a best practice for storing percentage data in a data warehouse? Should I add on the percentage calculations at the fact table level? I am trying to make the data warehouse design as simple as possible for the report writers.

    Hi Adrienne,
    IMHO, warehouses should never store a percentage. They should store the components that make up that percentage. For example, the warehouse should not store "% of total sales" column, but should instead store sales $ amount and from there analytics can be performed to calculate a percentage. A data mart is more of a place where you would materialize calculations, like %, for easier reporting.
    That being said, straight-up warehouse design questions are better suited over Warehouse Builder
    Good luck and hope that helps!
    -Joe
    Edited by: Joe Bertram on Dec 17, 2009 1:06 PM
    Edited by: Joe Bertram on Dec 17, 2009 1:06 PM

  • Need help with scenario design

    I need to design a scenario,
    Data is coming from two tables in mainframe.....that data i need to combine and process it and insert to ECC.
    How to design?.
    What will be the steps using BPM?.
    Can u please give me broad view on designing this scenario.

    Thanks Prabhu..for the input.
    Thanks Bhavesh. You got the point...that is what i am going to do.
    I have a select with join....then i update the records selected from database.
    But now, i want to resign the scenario..
    What i want to do is...write a sync send. Then use the join sql to get data, send to BPM.
    Then inside BPM, use select with for update only and update sql.
    For getting records on fly and send to BPM, how can i do?. Can u please elaborate this?.
    What all i need to do to run the join sql against table and get data to BPM?.
    (Advanced mode in JDBC Adapter setting to serializable queries is not working). So i need to do this step to overcome.

  • OBIEE 11G help with report design

    Hi,
    I need to design a report in the following format
    Customer Number:
    Customer Name:
    Customer Address:
    Order Detail:
    Line number | Order No | Order description | Order Status
    The order detail will have multiple lines, I have to do this in both Excel and PDF, is it possible to do without Publisher, and just OBIEE 11G? If so please help on how to do it?
    Thanks for your time and help.

    Hi,
    You can have static text or narrative view to achieve the customer details.
    And use the table format for the order details.
    And give reports links where in, you can download to both excel and pdf.
    Hope this resolves.
    Regards
    MuRam

  • Need help with DB design

    Hello,
    We are planning to use berkeley db to store mesurament data but I'm new to this.
    The data consists of device id (which made measurement), timestamp (when) and mesured value. Basic queries are "get all data from timestamp1 to timestamp2 for device with 'id' " and "get all data from timestamp1 to timestamp2 for devices with id1, id2, id3 ".
    I thought about "timestamp" as key and ("id", "value") as value and check id. But in case of hundreds or sousends of devices it could derate performance.
    Are there another way ?
    TIA for any suggestion :)

    From high-level, you could also try out these options -
    - you may want to look into creating a interval tree index and employ BDB's B+ tree for storing/retrieving the index.
    - you may also look into using the SQL interface of BDB, use R*-index to store intervals. This would let you use SQL for range queries for timestamps. For this, you would be required to compile sqlite with Rtree enabled.
    For performance, I guess you have to try first to get something to benchmark against.
    Hope it helps.
    Rupesh

  • Help with LiveCycle Designer ES 8.2

    I created a form in LiveCycle Designer ES 8.2 with a digital signature field so that any one can open it and fill it in and add a signature in adobe reader x ver 10.1.3. However, any one that opens it gets an error that says, "the security settings on this document prevent adding text and/or placing a signature on it from Adobe Reader. To fill and sign this document you need to print it out." The whole point is to not print it out so how do I change the security settings so that anyone can digitally sign this document in Adobe Reader  X?

    The document additionally needs to be Reader-enabled with Acrobat Pro. In case someone else read this, Acrobat Standard is not capable of adding the digital signature usage right.

  • Need help with a design

    Hi All,
    I have a peculiar requirement and would appreciate your suggestions/inputs in designing this.
    The client needs a custom UI from where they can select the different letters/documents they want to generate. But they want to preview the document and make any changes to it before they print it.
    For example, the user select letter1, letter2 and letter4 to be generated. He clicks on the 'preview' button and the 3 documents (MS Word) are created. But he wants to change some data in one of the letters (for example 'Need by Date') and then when he is satisfied, he clicks on the 'Generate' button. The generate button should merge all the 3 documents (with the changes made by user) as 1 pdf and email it to a particular email account.
    I can handle the dynamic template and merge/delivery part, but how can I take care of the case where a user makes changes to the generated report? We are on EBS R12.0.6
    Any suggestions?
    Thanks,
    Ashish

    you need some kind of reverse engineering, client change generated report and the change should reflect to template
    use xsl templateEdited by: arjamit on Nov 4, 2009 1:47 AM

Maybe you are looking for