Locking access to methods...

Hello everyone,
I hope somebody can help me with this tricky question. Basically, I need to lock access to other threads while the invoking method thread is executing.
Given the code below:
public synchronized string doWork() {
   doSomeWork();
   doMoreWork();
}Will the methods doSomeWork() and doMoreWork() also be locked to other threads, and if not how can I lock them until doWork() finishes?
Thank you,
Sergio Bastos

That is, both methods will be locked as long as
doWork is executing.No they won't, will they? Another thread can still
call doMoreWork. It just can't call it via the main
function.You can e.g. read on this link:
http://java.sun.com/docs/books/tutorial/essential/threads/monitors.html
"A critical section can be a block or a method and is identified with the synchronized keyword. The Java platform associates a lock with every object and the lock is acquired when a critical section is entered."
doWork has the object lock when it is executing, and no one else will be able to acquire that lock as long as the method is executing.
Kaj

Similar Messages

  • User J2EE_ADMIN does not have access to method rpData

    Hello,
    I'm using SAP ECC6 SR3 on windows x64 platform.
    I try to launch report FP_PDF_TEST_00 in SE38 and I get following error message :
    Test Program: Version Information (for Analysis Only)                                                                                1
    *** SYSTEM ERROR
    ERROR CODE    :    100.102
    ERROR MESSAGE :
    SOAP Runtime Exception: CSoapExceptionFault : SOAP fault found in SOAP document  /User J2EE_ADMIN does not have access to method rpData./<ns1:com.sap.engine.services.ejb.exceptio
    SOAP Framework error: SOAP Runtime Exception: CSoapExceptionFault : SOAP fault found in SOAP document  /User J2EE_ADMIN does not have access to method rpData./<ns1:com.sap.engine
    I checked RFC ADS and it use J2EE_ADMIN to connect to /AdobeDocumentServices/Config?style=rpc.
    Connection test returns no error.
    Does anyone have an idea ?
    Regards,

    ADSUser could be locked as in this thread,
    ADS Error: User does not have access to method rpdata.
    Regards
    Juan

  • How to access class method in jsp page

    hi ,
    I am new to JSP . I want to access a method returning an arraylist
    of a class.
    this class i saved in WEB-INF>classes folder > where other classes like logonform , etc. are saved ....
    import stmt is <%@ page import="java.io.*, java.util.*, readXml " %>
    <% readXml rd= new readXml();
    Arraylist list=rd.parseDoc();
    %>
    It is not recognizing readXml class......
    Can any body help me in this regard......
    plz help .... i m in urgent need
    thanks in advance.......

    better to put class in a pkg inside webinf> classes folder ...
    but in my case constructor was not public......
    public readXml(){}
    now it works fine...... :)

  • Error while accessing EJB method from JSP

    Hi,
    I am trying to access a bean from a JSP and have the foll. code piece:
    String url = "t3://localhost:7001";
    public Context getInitialContext() throws Exception {
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, url);
    return new InitialContext(p);
    String getStackTraceAsString(Exception e)
    // Dump the stack trace to a buffered stream, then send it's contents
    // to the JSPWriter.
    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
    e.printStackTrace(new PrintWriter(ostr));
    return(ostr.toString());
    %>
    <%
    String op="";
    try {
    // Contact the AccountBean container (the "AccountHome") through JNDI.
    Context ctx = getInitialContext();
    out.println("initial context got !!");
    DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
    out.println("home got !!");
    %>
    <p>
    <%
    Demo ac = null;
    try {
    ac = (Demo) home.create();
    out.println("create called!!");
    if (ac==null)
    out.println("ac is null!");
    catch (Exception ee) {
    out.print("exception 1");
    %>
    <p>
    <%
    try {
    out.println("going to call method!");
    if (ac!= null)
    op = ac.demoSelect(); /* FAILURE POINT */
    else
    out.println("ac is null->error!!");
    out.println(ac.demoSelect());
    out.println("string got!!");
    out.println(op);
    catch (Exception e) {
    getStackTraceAsString(e);
    e.printStackTrace();
    out.println("error 2");
    catch(Exception e)
    out.println("error 3!");
    It gives an error on trying to access the method "demoSelect".
    e.printStackTrace gives the output:
    java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated in EJB 1.1. EJB 1.1 compli
    ant containers are not required to implement this method. Use java:comp/env instead.
    <<no stack trace available>>
    JSP output is as foll.-->
    getting initial context initial context got !! home got !!
    create called!!
    going to call method! error 2
    What is wrong???
    pls help!

    Greetings,
    Hi,
    I am trying to access a bean from a JSP and have the
    foll. code piece:
    <%
    String op="";
    try {
    // Contact the AccountBean container (the "AccountHome") through JNDI.
    Context ctx = getInitialContext();
    out.println("initial context got !!");
    DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
    out.println("home got !!");Though it doesn't seem to be the problem in this case, good EJB coding practices dictate that your code should be narrowing the home reference before calling any of it's methods (i.e. create(...) )... WebLogic may allow handling of its protocol objects in their native state, but other vendors do not... your application is not portable without narrowing.
    It gives an error on trying to access the method "demoSelect".
    e.printStackTrace gives the output:
    java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated inThe error is not in your JSP, but in the bean... it seems your bean is attempting to acquire its "environment properties" in the pre-1.1 style, when...
    EJB 1.1. EJB 1.1 compliant containers are not required to implement this
    method. Use java:comp/env instead. ...instead, it should be looking them up in its JNDI namespace.
    What is wrong???
    pls help! Regards,
    Tony "Vee Schade" Cook

  • Error while accessing getCSVreportdata method

    here is the code snippet:
    ArrayList inputParameters = new ArrayList();
    inputParameters.add("");
    ReportInput reportInput = new ReportInput();
    reportInput.setReportKey(1);
    reportInput.setUserKey(userKey);
    reportInput.setInputParameters(inputParameters);
    tcResultSet rs;
    rs =repopinf.getCSVReportData(reportInput);
    And on execution i recieved the following exception:
    ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException in method: public abstract Thor.API.tcResultSet com.thortech.xl.ejb.interfaces.ReportOperations.getCSVReportData(com.thortech.xl.vo.report.ReportInput) throws Thor.API.Exceptions.tcAPIException,java.rmi.RemoteException, causedBy:
    java.lang.ClassCastException: java.lang.String cannot be cast to com.thortech.xl.vo.report.ReportSPParameter
    Please highlight some details on the usage of the method.

    Greetings,
    Hi,
    I am trying to access a bean from a JSP and have the
    foll. code piece:
    <%
    String op="";
    try {
    // Contact the AccountBean container (the "AccountHome") through JNDI.
    Context ctx = getInitialContext();
    out.println("initial context got !!");
    DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
    out.println("home got !!");Though it doesn't seem to be the problem in this case, good EJB coding practices dictate that your code should be narrowing the home reference before calling any of it's methods (i.e. create(...) )... WebLogic may allow handling of its protocol objects in their native state, but other vendors do not... your application is not portable without narrowing.
    It gives an error on trying to access the method "demoSelect".
    e.printStackTrace gives the output:
    java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated inThe error is not in your JSP, but in the bean... it seems your bean is attempting to acquire its "environment properties" in the pre-1.1 style, when...
    EJB 1.1. EJB 1.1 compliant containers are not required to implement this
    method. Use java:comp/env instead. ...instead, it should be looking them up in its JNDI namespace.
    What is wrong???
    pls help! Regards,
    Tony "Vee Schade" Cook

  • How to access a method of a class which just known class name as String

    Hi,
    Now I have several class and I want to access the method of these class. But what I have is a String which contain the complete name of the class.
    For example, I have two class name class1and class2, there are method getValue in each class. Now I have a String containing one class name of these two class. I want to access the method and get the return value.
    How could I do?
    With Class.forName().newInstance I can get a Object. but it doesn't help to access and execute the method I want .
    Could anybody help me?
    Thanks

    Or, if Class1 and Class2 have a common parent class or interface (and they should if you're handling them the same way in the same codepath)...Class c = Class.forName("ClassName");
    Object o = c.newInstance(); // assumes there's a public no-arg constructor
    ParentClassOrInterface pcoi = (ParentClassOrInterface)o;
    Something result = pcoi.someMethod(); Or, if you're on 5.0, I think generics let you do it this way: Class<ParentClassOrInterface> c = Class.forName("ClassName");
    // or maybe
    Class<C extends ParentClassOrInterface> c = Class.forName("ClassName");
    ParentClassOrInterface pcoi = c.newInstance();
    Something result = pcoi.someMethod();

  • Locking access to serial ports

    I have two instruments on serial ports, and two independant VIs to control them. One VI may be running, or both, at any one time. The VIs may be running under LabView, or executables.
    I would like some simple and elegant way of ensuring that when I run the second VI, it cannot access whichever port is being used by the first VI. I have experimented with using the VISA Lock Async.vi, which should do exactly that. However, it seems to be possible to have two VIs lock access to the same port, without generating an error. I can only assume that the "lock" is for the application (LabView), not the VIs.
    I have looked at the synchronisation functions for a solution, but I can't see any reasonable way of using them. Semaphores are ok if you want to control access to a single port, but not the undefined list of ports that may be available on any given machine.
    I could use a global array variable containing a list of ports in use. Not very elegant though...

    CDancer a écrit:
    Thanks, guys, but I don't think you have understood my problem. Read the first sentence - 2 completely independant VIs, and 2 or more ports...
    I have written a program today using the globals option, which works very well. There should be a better way though.
    Chris
    ViLabWorks a écrit:
    It isn't exactly clear to me why this is about one port. How much does one serial port cost versus programming time? Or even if it is about 4 serial ports the same applies. For me there is no question, doing something perhaps difficult versus spending next to nothing to solve the problem.
    Well...
    Sometimes you need to access the same equipement from different places in your application, or from different applications...
    Usually I simply set/read a global "busy" boolean.
    One problem I would like to adress is the automatic detection of specific serial hardware. How is it possible to find the port on which some equipment has been connected ? Of course, a solution would be to try to connect to this equipment by sending a command and waiting for the proper answer. However, before doing that, you need to detect the available ports (VISA Find Ressource), then scan each port after setting the proper baud rate, byte length, parity, etc..., then close the port to make it available to another application. Unfortunately, within LabVIEW, this procedure may interfere with other vis already connected to other serial equipments, with impredictable results.
    Apart the solution proposed in my first post, I don't know a way of deciding if a port is already in use. May be I missed something ?
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How to access java method in JSP

    Hi all,
    I need to access java class (abstract portal component) method doContent() in a JSP which is under PORTAL-INF/jsp folder.
    I did
    <%@ page import = "com.mycompany.Aclass" %>
    <%com.mycompany.Aclass a = new com.mycompany.Aclass (); %>
    Aclass is coming as autofill/prepopulated with cntrl+space
    Till this time, it is working. no errors. But when I do
    a.
    a. (a dot) no methods are populating (autofill..cntrl+space) or If I forcebly add method a.doContent(req,res)... at runtime its giving error.
    It's not only with doContent method... Its with any simple methods in that class or any other class.
    (Other than doContent method in the APC java class are prepopulating/autofilling but giving error in runtime)
    Can anyone help me... how to access java method in JSP.
    I already gone through many SDN forum post... and implemented too---but no use I refered below forum thread
    Retrieve values from Java class to JSP
    URGENT! How to call a java class from JSP.
    Calling a java method from jsp file -
    this thread is same as my issue
    Thanks,
    PradeeP

    1st. The classes must be in packages. 2nd, the package that they are in must be under the WEB-INF/classes directory. 3rd Look on google and/or this site for web application deployment

  • Access DataControls methods in a java class

    Hi All,
    Jdeveloper Version 11.1.5
    I have created DataControls for SessionFacade web service.
    Inside the datacontrol there is a method getAllDepartments() which have a Return type which includes DaertmentId,DepartmentName,....
    I want to know how can i access this method inside a Java Class and create a list of only departmentId.

    You would need to add the method in the data control as a method action in your pageDef.
    After that, you could access the method as mentioned above.
    Thanks,
    Navaneeth

  • How to access a method in webservice catalogued component in BPM Process

    Hi
    Can anyone explain me how to access a method in webservice catalogued component in BPM Process using an imported jsp in bpm process.
    Thanks & Regards
    Ashish

    If Class B only has a reference to an Interface A, and that reference points to a concrete instance of Class A, then of course Class B can still call the method on Interface A. The method for concrete instance Class A is called behind the scenes.
    That's how interfaces work. That's what they're good for.
    Look at the code in the java.sql package for examples. Connection, Statement, ResultSet - all are interfaces. But behind the scenes you're using the concrete implementations provided by your JDBC driver. You don't know or care what those classes are or their package structure. All you do is make calls to the java.sql interface API, and it all works. - MOD

  • Problem configuring Adobe Forms: ADSUSER does not have access to method...

    I hope all of you are doing well...
    So here is a rundown on what is happening.
    Enviroment:
    Netweaver 7.0
    ECC 6.0
    Abap and Java stacks are installed on the same system.
    Problem:
    I am trying to configure Adobe Print forms and not Interactive forms. When I run the test: FP_PDF_TEST_00
    I get the following error:
    Error Code: 100.102
    SOAP Runtime Exception: CSoapExceptionFault : SOAP fault found in SOAP document  /User ADSUSER does not have access to method rpData./<ns1:com.sap.engine.services.ejb.exceptions.
    When I run the rpData test from the J2EE server I get the following response:
    HTTP/1.1 500 Internal Server Error
    Connection: close
    Server: SAP J2EE Engine/7.00
    Content-Type: text/xml; charset=UTF-8
    Date: Fri, 03 Oct 2008 15:56:51 GMT
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>User ADSUSER does not have access to method rpData.</faultstring><detail><ns1:com.sap.engine.services.ejb.exceptions.BaseEJBException xmlns:ns1='http://sap-j2ee-engine/client-runtime-error'>User ADSUSER does not have access to method rpData.</ns1:com.sap.engine.services.ejb.exceptions.BaseEJBException></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
    I would really appreciate all the help that I can get.
    Thanks...

    Thanks for the tip,
    I had actually gone through the note before and tried out a couple of tips that were suggested in the note. I am still having the issue and believe that it might be due to the fact that I do not have a Credentials file installed.
    I am applying for the credential and will see what happens.
    thanks,
    Saif

  • Problem accessing applet methods since 1.4.2_06

    Hello,
    I'm working with ie 6.0
    I'm accessing applet methods from javascript
    My applets were working fine until I installed the JRE 1.4.2_06 (I tested them with JRE 1.4.2_05 and it worked)
    Now, when I call an applet method from javascript, I have a javascript exception, as if the applet is not loaded, but I think it is : I can see it in the traces in the java console !
    I didn't modify the code, just the JRE.
    It doesn't work with jre 1.5 too
    Here a simple sample code that doesn't work with JRE 1.4.2_06 :
    APPLET :
    import java.applet.Applet;
    public class Test extends Applet
         public void test() {
              System.err.println("test");
    HTML :
    <html>
    <body>
    <script language="JavaScript">
         function myTest() {
              document.myform.test.test();
    </script>
    <form name="myform">
    <OBJECT NAME="test" WIDTH=500 HEIGHT=120 CLASSID="CLSID:8AD9C840-044E-11d1-B3E9-00805F499D93">
    <PARAM NAME="code" value="Test.class">
    <PARAM NAME="scripting" value="true">
    </OBJECT>
         <input type="button" value="test !!" onclick="myTest()">
    </form>
    </body>
    </html>
    If you have any suggestion ...
    Thanks

    It should work, what if you try the following:
    html file:
    <html>
    <body>
    <script language="JavaScript">
    function myTest() {
    try{
         document.myform.test.test();
    }catch(e){
         alert(e.description);
    function myTest1() {
    try{
         document.getElementById("test").test();
    }catch(e){
         alert(e.description);
    </script>
    <form name="myform">
    <OBJECT NAME="test" id="test" WIDTH=500 HEIGHT=120 CLASSID="CLSID:8AD9C840-044E-11d1-B3E9-00805F499D93">
    <PARAM NAME="code" value="Test.class">
    <PARAM NAME="scripting" value="true">
    </OBJECT>
    <input type="button" value="test !!" onclick="myTest()"><br>
    <input type="button" value="test with getelementbyID!!" onclick="myTest1()"><br>
    </form>
    </body>
    </html>
    applet:
    import java.applet.Applet;
    public class Test extends Applet{
    public void test() {
         System.err.println("test");
    public void init(){
         System.out.println("this is init");
    When you open the page it should say "this is init" in the java console
    if the test button doesn't work try the getElementById way.

  • Help:accessing beans method

    hello
    i have made one application in which i have made two beans under different packages. i am trying to access beans through jsp pages. i am able to access beans and their methods but when i add new method in bean and tried to access that method with different new jsp page say page1.jsp. I am not able to access new method though i am able to access old methods of same beans with this new jsp page. then i made new bean and copied that method in this new bean . then i tried to access that method of this new bean with page1.jsp and i am able to access it can any body guide me what is the reason for this. i want to run this method in old beran rather than new bean
    my directory structure is:
    projectlms---main folder
    addstream---old jsp page
    page1---new jsp page
    web-inf/classes
    com-------main packageof beans
    ProgramManager----sub package of classes
    bean1--------old bean
    new bean------new bean just for testing
    now the problem is that i want to add one more method to bean1 and want to access it through pag1.jsp
    but i am not able to access it and same method when i take to new bean i am able to access that method through page1.jsp
    but i am able to access old methods of bean1 through page1.jsp
    thanks
    regards
    vivek

    Could be a caching issue.
    Wipe out the COMPILED jsps and try again.

  • How to access private method of an inner class using reflection.

    Can somebody tell me that how can i access private method of an inner class using reflection.
    There is a scenario like
    class A
    class B
    private fun() {
    now i want to use method fun() of an inner class inside third class i.e "class c".
    Can i use reflection in someway to access this private method fun() in class c.

    I suppose for unit tests, there could be cases when you need to access private methods that you don't want your real code to access.
    Reflection with inner classes can be tricky. I tried getting the constructor, but it kept failing until I saw that even though the default constructor is a no-arg, for inner classes that aren't static, apparently the constructor for the inner class itself takes an instance of the outer class as a param.
    So here's what it looks like:
            //list of inner classes, if any
            Class[] classlist = A.class.getDeclaredClasses();
            A outer = new A();
            try {
                for (int i =0; i < classlist.length; i++){
                    if (! classlist.getSimpleName().equals("B")){
    //skip other classes
    continue;
    //this is what I mention above.
    Constructor constr = classlist[i].getDeclaredConstructor(A.class);
    constr.setAccessible(true);
    Object inner = constr.newInstance(outer);
    Method meth = classlist[i].getDeclaredMethod("testMethod");
    meth.setAccessible(true);
    //the actual method call
    meth.invoke(inner);
    } catch (Exception e) {
    throw new RuntimeException(e);
    Good luck, and if you find yourself relying on this too much, it might mean a code redesign.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • ADS Error: User does not have access to method rpdata.

    Hi All,
    I have done the ADS configuration according to ADS guide. But when I check the ADS using FP_PDF_TEST_00 report. First of all it is not taking ADSUser or ADS_Agent id. If I give J2EE admin id and password then I get following error:
    SOAP Runtime Exception: CSoapExceptionFault : SOAP fault found in SOAP document  /User J2EE_ADMIN does not have access to method rpData./<ns1:
    SOAP Framework error: SOAP Runtime Exception: CSoapExceptionFault : SOAP fault found in SOAP document  /User J2EE_ADMIN does not have access t
    Please help me on this.
    TIA,
    Amit

    Amit,
    Check this thread and see if it helps.
    Adobe Document Services - test method rpData with user ADSUser and Notes 959462, 944221.
    Chintan

Maybe you are looking for