Question about EJB and thread safe coding - asking again!

sorry everyone, no one seems to be interested in helping me on this, so i post it again.
i have a question about the EJB and thread safe coding. when we build EJBs, do we need to worry about thread safe issue? i know that EJBs are single threaded, and the container manages the thread for us. maybe i am wrong about this. if i wasnot, how can we program the EJB so that two or more instance of EJB are not going to have deadlock problem when accessing data resources. do we need to put syncronization in ours beans, do we even need to worry about creating a thread safe EJB? thanks in advance. the question really bothers me a lot lately.

sorry everyone, no one seems to be interested in
helping me on this, so i post it again.Excellent plan. Why not search a little bit on your own instead of waiting for your personal forum slaves to answer your call. See below.
i have a question about the EJB and thread safe
coding. when we build EJBs, do we need to worry about
thread safe issue? Read this: http://forum.java.sun.com/thread.jsp?forum=13&thread=562598&tstart=75&trange=15
i know that EJBs are single
threaded, and the container manages the thread for us.
maybe i am wrong about this. if i wasnot, how can we
program the EJB so that two or more instance of EJB
are not going to have deadlock problem when accessing
data resources. do we need to put syncronization in
ours beans, do we even need to worry about creating a
thread safe EJB? thanks in advance. the question
really bothers me a lot lately.
Java's Thread Tutorial
JavaWorld: Introduction to Java threads
IBM: Introduction to Java threads
Google: java+threads+tutorial

Similar Messages

  • Specification/Architectural question about EJBs and XML

    Hello,
    My problem is as follows: I would like for a session ejb to retrieve information from xml files (other that the ejb DDs of course...). I prefer the XML-file solution to the relational-database solution as it is more lightweight. (We haven't got the resources nor the skill to administrate a native xml database.) Am I allowed to read from the filesystem? What is the best architectural solution you would advise bearing in mind I need the information contained in the xml files to be available in java (in the session bean). Ideally I would drop xml files in a directory and they would automatically be parsed and taken into account by an ejb.
    I am available to provide more details if needed.
    Any clue welcome,
    Julien Martin.

    Hello,
    My problem is as follows: I would like for a session ejb to retrieve information from xml files (other that the ejb DDs of course...). I prefer the XML-file solution to the relational-database solution as it is more lightweight. (We haven't got the resources nor the skill to administrate a native xml database.) Am I allowed to read from the filesystem? What is the best architectural solution you would advise bearing in mind I need the information contained in the xml files to be available in java (in the session bean). Ideally I would drop xml files in a directory and they would automatically be parsed and taken into account by an ejb.
    I am available to provide more details if needed.
    Any clue welcome,
    Julien Martin.

  • Question about EJB and Poject Management for a Company

    In my Company we have some problems with the management of Java Projects and
    EJB Projects. Alot of code is not reused but written again, cause noone manages it.
    Are there any programs or guides (guidelines) who can support us with these problems?
    How do you handle these problems?
    Thanks

    In my Company we have some problems with the
    management of Java Projects and
    EJB Projects. Alot of code is not reused but written
    again, cause noone manages it.
    Are there any programs or guides (guidelines) who can
    support us with these problems?
    How do you handle these problems?I guess you should take a look at core J2EE patterns during the design. :)
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html

  • A few questions about MacBooks and Parallels Desktop.

    I have a few questions about MacBooks and Parallels Desktop.
    1) I understand I need at least 1GB of RAM to run Parallels Desktop but what about the hard drive, is the stock 60GB drive big enough?
    2) Related to question 1, even if it was big enough to allow me to install and run Windows would the 60GB drive be enough if I wanted to install a Linux distribution as well?
    3) This has nothing to do with Parallels Desktop but thought I'd ask it here anyway, do Apple Stores carry just the stock MacBooks, or do they carry other configurations?
    Thanks
    Keith

    1. Depend on how intensive you use that HD for saving data on both Mac OS and XP. For standard installation on both OS X and XP, the space of 60 Gb is enough.
    2. Same answer as no 1. You can install all three on that HD space, but the extra spacce available will be less and less for your data. You can save your data on external or back up on cd/dvd and erase it from the HD to keep the free space.
    Remember to leave at least 2 or 3 Gb for virtual memory usage.
    3. Just call them, maybe they don't have it in store stock, but by appointment they might configure one for you before your pick-up date.
    Good Luck

  • One question about Pricing and Conditions puzzle me for a long time!

    One question about Pricing and Conditions puzzle me for a long time.I take one example to explain my question:
    1-First,my sale order use pricing procedure RVAA01.
    2-Next,the pricing procedure RVAA01 have some condition type,such as EK01(Actual Costs),PR00(Price)....,and so on.
    3-Next,the condition type PR00 define the Access Sequences PR00 as it's Access Sequences.
    4-Next,the Access Sequences PR00 have some Condition tables,such as:
         table 118 : "Empties" Prices (Material-Dependent)
         table 5 : Customer/Material
         table 6 : Price List Type/Currency/Material
         table 4 : Material
    5-Next,I need to maintain Condition tables's Records.Such as the table 5(Customer/Material).I guess the sap would supply one screen for me to input the data of table 5.At this screen,the sap would ask me to select one table,such as table 5.When I select the table 5,the sap would go to the screen to let me input the data of table 5.But when I use the T-CODE VK31 or VK32 to maintain Condition tables's Record,I found it's total different from my guess:
    A-First,I can not found one place for me to open the table,such as table 5,to let me input the data?
    B-Second,For example,when I select the VK31->Discounts/Surcharges->By Customer/Material,the sap show the grid view at the right side.At the each line of the grid view,you need to select the Condition Type at the first field.And this make me confused very much.Why the sap need me to select one Condition Type but not the Condition table?To the normal logic,it ought not to select Condition table but not the Condition Type!
    Dear all,I'm a new one in sd.May be this is a very stupid question.But it did puzzle me for a long time.If any one can  explain this question in detail and let me understand the concept,I will appreciate him/her very much.Thank you.

    Hi,
    You said that you are using the T.codes VK31 or VK32.
    These transaction codes are used to enter condition records for standard condition types. As you can see a grid left side having all the standard condition types like price, discounts, taxes, frieghts.
    Pl check using T.code VK11 OR VK12 (change mode)
    Here you can enter the required condition type, in the intial screen. (like PR00, MWST, K004, K005 .....etc)
    After giving the condition type, press enter or click on Combinations icon on top of the screen. Then you can see all the condition tables which you maintained for that condition type. Like as you said table 118, table 5, table 6 and table 4.
    You can select any table and press enter, then you can go into the screen in which you have all the field cataglogues you maintained for that table. For example you selected combination of Customer/Material (table 5) then after you press enter then you can see customer field on top, and material fields.
    You can give all the required values and save the conditon record.
    Hope this is clear.
    REWARD IF HELPFUL.
    Regards,
    praveen

  • Okay i just recently asked a question.about my factory unlocked iphone 3gs asking how to activate it but..

    i probably shouldnt say this but,okay i just recently asked a question.about my factory unlocked iphone 3gs asking how to activate it. so i got too excited of aving it and couldnt wait for my tmobile sim card to come  one more day. so i "hactivated" it (i know this voids all warrenty) and i jailbroke it just so i could use it as an ipod.it worked and i was syched.
    BUTTT.... it asked me if i wanted to update the software to 5.1 and i was like " oh yes id love to" and it started downloading it and it was inrecovery mode the whole time .
    when the download finished. i hit restore so i can put the software on the phone but the itunes had an error and the phone went glitchy and it does a rebooting loop. it shows the apple symbol with the slash through it for about 5 seconds and shuts off for a little bit (about another 5 seconds) and it starts up  then loops the process. ive managed to turn the phone off but if i start  it up it loops...what should i do? any help :/
    Also it does not show up in my itunes because it is turning off to fast to detect.

    Discussion of hacked phones is prohibited on these forums.  Sorry, you'll need to go elsewhere to get support for a j'broke iPhone.

  • A question about grub and USB

    Hi All
    I have a quick question about grub and USB that I can't quite find the answer to by searching.   Most of the FAQs discuss booting a full linux dristribution from USB. My situation is this.  I am getting a new computer with two drives, the second will be arch and the first will be Vista (for my wife).  I want the computer to boot the same way that my wife's machine boots at work so I don't want to install grub on the MBR.  So, is there a way to have all of the grub config files and kernels installed on the second drive and simply install to grub boot loader to the MBR of a USB stick?  My goal would be to simply plug the USB stick into the new PC and boot arch from the second drive. 
    Thanks
    Kev

    i cant say for hp's
    havent worked on any in a while
    recent machines have been coupleof dell's , vaio & emachine
    which dells do offer it at least the ones i tried , my laptop does(dell)
    all home pc's are built by me which do offer to boot individual drives
    what hp you getting it may tell in specs
    are both discs sata? if so it might not offer this option with 2 drives of same interface
    check your power supply alot of these preconfigured machines put cheap under reated power supplies in there
    & will burn your motherboard i just replaced PS(250 watt) & mobo(845gvsr) in an emachines <cheap stuff<
    i hope you researched the pc before buying ie : mobo, power supply are the biggest concerns
    i find it much more benificial to build my own machine gives me peace at mind. the cost is sometimes more in $ but not always , your biggest expense is time researching hardware
    if you live in usa the best places to start looking are bensbargains.net & pricewatch.com
    i am not affiliated with either & niether sell the hardware they are just advertisers a place to buy
    for costomized machines that i would trust is unitedmicro.com theyll asemble & test before shipping
    i have gotten 2 machines so far from them with NO PROBLEMS with hardware (knock knock)
    you may want to consider this in your next venture for pc

  • I have a Macbook Pro june 2011... I have 8GB ram but I only have 256mb VRAM... I've read some other questions about this and I realized... Why do I not have 560mb of VRAM since I have 8GB of RAM? Is there any way to get more VRAM to play games on steam?

    I have a Macbook Pro june 2011... I have 8GB ram but I only have 256mb VRAM...
    I've read some other questions about this and I realized... Why do I not have 560mb of VRAM since I have 8GB of RAM?
    Is there any way to get more VRAM to play games on steam?
    I've learned  by reading other topics that I can't upgrade my graphics card on my Macbook Pro because it's soldered into the motherboard or somthing like that, but please tell me if there is any way to get more video ram by chaning some setting or upgrading something else. I'd also like to know why I only have 256MB of VRAM when I have 8GB of RAM, since I have 8GB of RAM I thought I was supposed to have 560mb of VRAM...
    So the two questions are...
    Is there any way to upgrade my VRAM, so that I can play games on steam?
    Why do I only have 256MB VRAM when I have 8GB total RAM?
    Other Info:
    I have a quad core i7 Processor.
    My graphcics card is the AMD Radeon HD 6490M.
    I am also trying to play games on my BOOTCAMPed side of my mac, or my Windows 7 Professional side.
    THANK YOU SO MUCH IF YOU CAN REPLY,
    Dylan

    The only two items that a user can change on a MBP are the RAM and HDD (Retinas not included).  You have what the unit came with and the only way you will be able to change that is to purchase a MBP with superior graphics
    If you are very much into gaming, the I suggest A PC.  They are far superior for that type of application to a MBP.
    Ciao.

  • 2 question about GPU and Lens correction ,cs5

    Hi
    i have 2 questions about Gpu and lens correction in Cs5
    1)Filter->lens correction->search online
    i get often and almost every connection time out at the first click on search online , at the second click i get no online profile
    is it normal?
    2) question is about Gpu
    it run faster , but talking about ajustament layer
    like saturation or vibrance for example
    i found with the gpu on , a light slow refresh compared with gpu off
    i have set cache  levels 6 ,history 20
    i guess are the defaul
    well i add a saturation layer and move the saturation slide ,increase o decrease saturation
    with Gpu Off , the changes are immedially , i mean i can see in real time the increase o decrease of saturation
    with Gpu On it takes a few(very few) time more
    again is normal ?
    don't be angry , i'm going to buy cs5 and i'm unsecure ... the price make a big role
    thanks

    For what it's worth, I also see a timeout on the first [ Search Online ] click, after about half a minute delay.  Second click turns up results immediately.  This happens each time Lens Correction is started, even without restarting Photoshop, and in both 32 and 64 bit versions.  Also note that I started with one profile listed by default (though from the wrong camera) for my 40D with 28-135 zoom.
    I alsow noticed that I was seeing progress bar activity in the Lens Correction dialog while I was typing this (even though Lens Correction was NOT the active window) every time I hit the 'L' key.  Strange.
    Windows 7 x64.
    -Noel

  • Three questions about Java and Ftp

    Hello, i've the following questions about Java and Ftp:
    1- .netrc file is in $HOME directory but i can't access to this directory from java code. The following line producesan Exception (directory doesn't exists)
    FileWriter file = new FileWriter ("$HOME/.netrc");
    2- .netrc file must have the following permissions: -rw- --- --- but when i create the .netrc file the following permissions are on default: -rw- r-- r--, how can i change this permissions? (In java code, i can't use chmod.....)
    3- Are there any way to pass parameters to a .netrc file? If i get to do this i needn't change the permissions because i can't modify or create/destroy this file.
    Thanks in advanced!!!
    Kike

    1- .netrc file is in $HOME directory but i can't
    access to this directory from java code. The
    following line producesan Exception (directory
    doesn't exists)
    FileWriter file = new FileWriter ("$HOME/.netrc");$HOME would have to be replaced by a shell, I don't
    think you can use it as part of a legal path.
    Instead, use System.getProperty("user.home");
    Ok, thanks
    2- .netrc file must have the followingpermissions:
    -rw- --- --- but when i create the .netrc file the
    following permissions are on default: -rw- r--r--,
    how can i change this permissions? (In java code,i
    can't use chmod.....)Yes, you can: Runtime.exec("chmod ...");
    I need to use estrictly the .netrc with -rw- --- --- permissions
    Yes, i can use Runtime.exec ("chmod ..."); but i don't like very much this solution because is a slow solution, am i right?
    3- Are there any way to pass parameters to a.netrc
    file? If i get to do this i needn't change the
    permissions because i can't modify orcreate/destroy
    this file.I don't think so. Why do you need the .netrc file in
    Java at all? Writing a GUI frontend?I want to use automatic ftp in a java program and FTP server, the files and path are not always the same, so i can:
    - modify .netrc (for me is the complex option)
    - destroy and create a new .netrc (is easier but i have permissions problem)
    - use .netrc with parameters but i haven't found any help about it
    Thanks for your prompt reply!!!!
    Kike

  • Are i++, i-- atomic and thread safe for int i

    I want to minimize the sync time multiple threads take to contend for a shared pool, which is implemented as a FIFO. My plan is to:
    1. Use a int variable "count" to trace the free obj count. Hence eliminates the need of synchonized methods size() and isEmpty()
    2. Increment & decrement count when implemeting push() and pop()
    3. Minimize the number of statements in synchonized block as possible within push() and pop(), which in this case, excludes count++ and count-- provided these operations are atomic and thread safe
    Have I lost something ?

    So, may I make a conclusion.
    To minimize contention, I use FIFO instead LIFO or stack and build it from scratch without extending from existing Collection-related class
    1 public class FIFO {
    2 . . private volatile int count;
    3 . . private Object head, tail;
    4 . . public Object pop() {
    5 . . . .synchonized (tail) {
    6 . . . . .if (count >= 3) {
    7 . . . . . .Object tail_origin = tail;
    8 . . . . . .// Re-organizing the linked list skipped
    9 . . . . . .synchonized (this) {
    10 . . . . . . count--;
    11 . . . . . }
    12 . . . . . return tail_origin;
    13 . . . . }
    14 . . . . else {
    15 . . . . . throw new PoolEmptyException();
    16 . . . . }
    17 . . . }
    18 . . }
    19 . . public void push(Object o) {
    20 . . . synchronized (head) {
    21 . . . . . // Re-organizing the linked list skipped
    22 . . . . . head = o;
    23 . . . . . synchonized (this) {
    24 . . . . . . count++;
    25 . . . . . }
    26 . . . }
    27 . . }
    28 . . public int sizeOf() {
    29 . . . return count;
    30 . . }
    31 }
    1. The reason I choose FIFO is to avoid the contention between push() and pop() -- they are NOT declared as synchonized, instead they only lock head and tail respectively. (Sorry I borrow the name push and pop from stack)
    2. pop() only works when count >= 3 to avoid head == tail after pop() and hence a further call to push() block concurrent call to pop() and vice versa (see line 5 and 20)
    3. The goal is to minimize the time and scope of contention. In line 9 and 23, I lock the whole pool object only when modify count, which is not atomic.
    4. This pool is used for a thread pool supporting many concurrent short-lived HTTP request
    Have I missed something ?
    Thanks a lot!

  • Basic question about storage and safety in iMovie '11

    A very basic question about storage and safety:
    I want to keep a backup of my raw footage on my external hard drive prior to begin working on the movie in iMovie. I want to do this:
    1. Upload the digital files from my camcorder to my Desktop *(as opposed to iMovie)*
    2. Duplicate that footage/clips.
    3. Put the duplicate clips/footage into a folder labeled with the name of that footage (like "Fun At the Dentist" or "Jimmy Learns How to Yodel").
    4. Drag the folder with the footage/clips into my external hard drive into a pre-existing folder titled "Backups/duplicates of all of my raw footage/clips." This big granddaddy folder will house all of the child folders of different movies.
    5 Then, open up iMovie '11 and import the raw footage/clips from my Desktop rather than from my camcorder.
    6. Then I want to make a duplicate of my finished movie and put it in my external hard drive in a "Finished Movies" folder.
    I know that the original raw unedited footage will always be in iMovies '11 but I want the original to also exist immediately accessible in my external hard drive.
    QUESTION:
    Is this viable? Is it wise? (I know it goes an extra unnecessary step, but aside from that.)
    *Do you have any precautionary advice?* Should I do something in my iMovies '11 preferences? What?
    In earlier years with iMovie '04 or '06 (cannot recall) I made many novice errors and ended up losing audio to my finished movie. I also lost footage.
    This time around with iMovie '11 I don't to make such novice, ignorant errors.
    Thanks so much for any comments to this question.
    -L

    Yes I'm sure it will work great for you.
    The iFrame format is something Apple has come up with. The reason for its existence is unknown to me so I can only speculate. But it seems to me that Apple "invented" this format in order to have devices such as Ipod/Ipad/Iphone/Ixxx create clips that are editable on consumer hardware such as already mentioned devices but also standard Mac computers, without the need for format conversion.
    iMovie converts most input formats during import, which takes a lot of time, and this need for conversion often comes as a surprise to most people new to home video editing.
    iFrame has a resolution of 960x540 which is long way from the common standards of 1920x1080 and 1280x720. If your end target is YouTube however, this may not be too bad though. However if you intend to go with YouTube HD, you may find iFrame footage to look wrong since they are effectively upscaled to a higher resolution.
    Technically iFrame uses the H.264 algorithm, a smaller frame size (960x540) and a rather low compression scheme. This will result in large files, but the plus side is that the files are ready for editing without the need for any conversion and iMovie will natively edit the files.

  • Question about RAC and ASM

    Hi,
    We are thinking about build RAC using ASM for OEM database. It'll have two nodes, oracle 10g and Hitachi san with solaris ( or linux ). I've few questions about RAC and ASM.
    1) Do I need to have ASM instance running on each node ? ( most likely yes... but want to make sure )
    2) can I share oracle_home between ASM instance and database instance ? what is the best choice ?
    3) I'm planning to use shared disks for all files, all databases.... what are the pros/cons ?
    4) what should be the installation procedure ? Meaning, first create ASM instance on each node, then install cluster software, build RAC databases...... can someone explain..
    5) I believe RMAN is the only option for backup since I'm using ASM, correct ?
    I'm a newbie to RAC and ASM..
    Thanks,

    user4866039 wrote:
    1) Do I need to have ASM instance running on each node ? ( most likely yes... but want to make sure )yes.
    2) can I share oracle_home between ASM instance and database instance ? what is the best choice ?in 10g you can, in 11gr2 you cannot. and it might be better to seperate them because it will give you more flexibility with patching.
    3) I'm planning to use shared disks for all files, all databases.... what are the pros/cons ?if you share your oracle_home you won't be able to do rolling updates. so i recommend to keep oracle_homes local.
    4) what should be the installation procedure ? Meaning, first create ASM instance on each node, then install cluster software, build RAC databases...... can someone explain..follow the install guide for your respective version. for 10g you'd install clusterware first, then asm and database is last.
    5) I believe RMAN is the only option for backup since I'm using ASM, correct ?pretty much. you could stop your database and dump the raw devices or use asmcmd/asmftp but rman is definitely the best choice
    Bjoern

  • Urgent: Question about Censoring and replacing

    Hello, guys.
    This is my very first time writting a java program. Please tell me what I have done wrong as this is my first time?
    My question is to write a program that asks the user for a word to replace in some text, and the word to replace it with. The program then reads a line of text from the user and echoes the line back to screen replacing all occurrences of the first word with the second word. It only replaces the word being censored when it occurs independently in a line (i.e. not as a part of another word).
    Like:
    Enter word to censor: dumb
    Enter word to replace it: xxxxx
    Enter line of text to censor:
    The guy is dumb but his friend is even dumber.
    The guys is xxxxx but his friend is even dumber.
    Please look at my code now and tell me what is wrong?
    public class censor
       public static void main(String args[])
           String sentence = "Please type a word which you like to censor"
           String ac =  string sentence;
           String[] temp = null;
           temp = sentence.split(" ");
           for (int j = 0; j < temp.length; j++ )
               if (temp[j].equals("bridge"))
                   string sentence = "Censored";
               System.out.println(sentence + " " + string sentence);
    } Edited by: G on Apr 13, 2008 4:04 AM
    Edited by: KevinGupta on Apr 13, 2008 4:05 AM

    Hey guys,
    I'm getting an error where I have added the "ERROR LINE" next to the line where im getting an error..
    What I'm trying to do ?: I'm trying to make it like
    Enter word to censor: dumb
    Enter word to replace it: xxxxx
    Enter line of text to censor: The guy is dumb dumb dumb dumb and his friend is dumber.
    So, this code should replace ALL "dumb" with xxxxx NOT the dumber. But when I try to run this code only one dumb changes to xxxx not all ? So, please help on that. Also, this code doesnt work when I try to write " LIke ThaT " It gives me an exception error ?
    {color:#ff0000}Look at the error below (underneath the code){color}
    import java.util.*;
    public class LineCensor
    public static void main(String [] args)
    System.out.print("Enter a word to censor: ");
    Scanner keyboard = new Scanner(System.in);
    String word = keyboard.nextLine();
    System.out.print("Enter a word to replace it: ");
    String wordC = keyboard.nextLine();
    System.out.println("Enter line of text to censor: ");
    String phrase = keyboard.nextLine();
    String wordLowered = word.toLowerCase();
    String phraseLowered = phrase.toLowerCase();
    int location = phrase.indexOf(word);
    String string1 = phraseLowered.substring(location,(location +
    wordLowered.length()));
    String string2 = phraseLowered.substring(0, location);
    String string3 = phraseLowered.substring(location+word.length());
    System.out.println(string2+wordC+string3);
    string2 = string2.toLowerCase();
    for (int i=0; i < phrase.length; i++)
    (phrase.equals());                        <-------- ERROR LINE.
    phrase = wordC;
    System.out.println(+i);
    }ERROR:
    The error is:
    LineCensor.java:28: not a statement
    (phrase.equals());
    ^
    1 error ANOTher ErroR
    Enter a word to censor: CaT
    Enter a word to replace it: xxxx
    Enter line of text to censor:
    The cAT wAs CuRioUs abOuT otHER CAT's strings
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1932)
    at LineCensor.main(LineCensor.java:17) This error is coming up because of lower and high caps typing. This shouldnt be happening no matter how I type the sentence/word.
    Please help ?
    Edited by: kabootar on Apr 16, 2008 3:20 AM
    Edited by: kabootar on Apr 16, 2008 3:21 AM

  • Question about "synchronized" and "wait"

    Hello, everyone!
    I have seen a piece of code like this,
    synchronized (lock)
    //do operation 1
    lock.wait();
    //do operation 2
    I think in the above piece of code, when a thead finished operation 1, it will release the lock and let other threads waiting for the lock have chance to run the same block of code. Am I correct?
    If I am correct, I have a further question, a "synchronized" block means a set of operations that can not be interrupted, but when invoke "wait" method, the thread running in the "synchronized" block will be terminated (interrupted) by release the lock and other threads will have chance to enter the "synchronized" block. In short, the execution inside the "synchronized" block will be interrupted. So, I wonder whether the above piece of code is correct and conforms to the principle of "synchronized". And what is its real use?
    Thanks in advance,
    George

    Thanks, pkwooster buddy!You're welcome
    I just wondered whether "wait inside a synchronized
    block" technology is thread safe. Please look at the
    following example,wait and synchronized are thread safe.
    public class Foo {
    int mVal= 0;
    public final Object mLock = ...;
    public void doIt() {
    synchronized(mLock) {
    mVal = ...;
    mLock.wait();
    if (mVal == ...) {
    // do something
    } else {
    // do something else
    }If we have two threads, T1 and T2, enter the block in
    their respective order, and T1 is woken up first, T2
    may have tampered with T1's execution path because T2
    changed mVal while T1 was asleep. So T2 manipulate
    instance field mVal is a side-effect.when you do the wait() you give up the lock and the other threads get a chance to run. When you exit the wait() you get the new value of the myVal variable which may have been changed. This is exactly what you want. To make that not thread save you could do
    int temp = myVal;
    wait();
    if(temp == ...)in this case the variable temp contains the old vale of myVal.
    >
    I think the most safest way is never wait inside a
    synchronized block, but it is less efficient. What do
    you think about the trick of wait inside a
    synchronized block? I think you are very experienced
    in thread field from your kind reply.
    Thanks in advance,
    Georgewait(), notify() and notifyAll() are very useful. You need them when you want threads to cooperate in an predictable manner. I recommend that you review the section on consumer and producer classes and wait and notify in the Threads Tutorial. It gives good examples. For a practical example of this you could also take a look at my Multithreaded Server Example. It implements a simple chat server that switches String messages. Look especially at the send(), doSend() and popMessage() methods in the StreamConnection class. These allow the receive thread of one user to send messages out using the send thread of another user. If you have questions about that example, please post the questions on that topic.
    Hope this helps.

Maybe you are looking for

  • Hashmap and array list problems

    This is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go from here. Any guidance would be very welcomed. We were given code that used just an Array lisTh

  • Problems in 3d only - 680i & X-Fi ExtremeGamer

    Upgraded to the X-Fi FPS from the onboard HD audio on my setup: EVGA 22-CK-NF68-AR (p26) Intel Core 2 Quad Q6600 Kentsfield 2.4GHz (stock speed\cooling) EVGA 52-P2-N635-AR Geforce 7950GT KO 52MB GDDR3 PCI Express x6 (stock speed\cooling) CORSAIR XMS2

  • How to connect to Agilent DSO7104 through USB connection

    I want to connect to Agilent oscilloscope DSO7104 using USB interface. I have installed labview 8.0, ag6000a Instrument Driver and visa4.6.2. When I use Example of ag6000a Instrument Driver, the VISA resource name are COM1, COM3 and LPT1. What should

  • Help - Debit & credit note creation scenarios.

    can anyone help me learning Debit & credit note creation scenarios.any online manual can be of much helpful.immediately required. thanks in advance. Sincerely Ajith.

  • Form Guide - Repeating Area(s) within a Panel

    Hi, Just wondering if its possible to have more than one repeating area within the same panel? I have been able to create the Panel with a comment at the top (using guide text) followed by my repeating area and finally another comment followed by som