Synchronized method in a java class used by many interfaces

My interface (idoc to file) is using a java class, which has one method that reads a table from a central database and after doing some calculations updates it.
(The interface instantiate the class inside a user-defined function and calls the method there.)
The problem is that if somebody sends 100 idocs at the same time, there can be a “dirty read”, I mean, a read just before other interface updates the table.
We want the following:
Interface 1:
-          Read counter from the table (counter = 5 )
-          Increment counter (counter = 6)
-          Update table with that counter (table with counter = 6)
Interface 2:
-          Read counter from the table (counter = 6 )
-          Increment counter (counter = 7)
-          Update table with that counter (table with counter = 7)
RESULT: The table has the counter = 7
But what is happening is the following:
-          Interface 1 reads (counter = 5)
-          Interface 2 reads (counter = 5)
-          Interface 1 increments counter (counter = 6)
-          Interface 2 increments counter (counter = 6)
-          Interface 1 updates table (table with counter = 6)
-          Interface 2 updates table (table with counter = 6)
RESULT: The table has the counter = 6 (WRONG)
I made the method synchronized. What I was expecting was that only one interface (i1) could enter the method (read the table and update it) while other interfaces running at the same time would have to wait until i1 finished that method.
My first test indicates that's not happening. Can anybody help me to find a solution?

Hi Bhavesh,
If the QOS is EOIO this means that the integration engine manage the call to the mapping program (and all the other blocks) inside an "internal" synchronized method.
So this means that in this case you do not need to manage the queued access (synchronization) inside your custom java code because it is already enveloped in a queued block by XI.
The problem that Jorge had can be easily reproduced using the sample code that follows:
<b>class Synch Object</b>
import java.util.Date;
public class SynchObject {
     String strName;
     public SynchObject(String strName){
          this.strName = strName;
     public synchronized void syncWrite(String strCaller) throws InterruptedException{
          Date now;
          now = new Date();
          System.out.println("-- " + now.toLocaleString() + " " + strCaller + " entering syncWrite of " + strName);
          System.out.flush();
          Thread.sleep(1000);
          now = new Date();
          System.out.println("-- " + now.toLocaleString() + " syncWrite of " + strName + " called by " + strCaller );
          System.out.flush();
          Thread.sleep(1000);
          now = new Date();
          System.out.println("-- " + now.toLocaleString() + " " + strCaller + " leaving syncWrite of " + strName);
          System.out.println("");
          System.out.flush();
<b>class Caller</b>
public class Caller implements Runnable {
     String strName;
     SynchObject target;
     int intMax;
     public Caller(String strName, SynchObject target, int intMax) {
          this.strName = strName;
          this.target = target;
          this.intMax = intMax;
     public void run() {
          for(int i=0; i<intMax;i++)
               try {
                    target.syncWrite(strName);
               } catch (InterruptedException e) {
                    e.printStackTrace();
<b>class Workbench</b>
public class Workbench {
     public static void main(String[] args) {
          // TODO Auto-generated method stub
          SynchObject sObj1 = new SynchObject("syncObj1");
          SynchObject sObj2 = new SynchObject("syncObj2");
          Caller c1 = new Caller("caller1",sObj1,2);
          Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
          Thread ct1 = new Thread(c1);
          Thread ct2 = new Thread(c2);
          ct1.start();
          ct2.start();
Run the workbench class to see what happen when setting QOS EOIO (the synch object is the same).
To see instead what happen now (missing synchronization) you have to change in Workbench class the statement
Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
with
Caller c2 = new Caller("caller2",sObj2,2); '[*CHANGE*]
The reason is that every instance of the mapping program declare a new instance of the "Synchronized object" so the calls are synchronized inside the same mapping program but not between several mapping program.
Hope this give you a better idea on this problems with java synchronization, but if you have further doubts (I know it's a little bit tricky ) feel free to ask.
Kind Regards,
Sergio

Similar Messages

  • Accessing Java Class using JNDI

    Hi,
    I am looking for a way for accessing a java class (non-ejb) and invoking a method in it using JNDI.
    Thanks

    See if the follwing helps u
    1).implement Referencable interface for your java class. Implement serialize interface also.
    2).Referencable interface has a methd referencable() which will be invoked by JNDI naming system when a lookup is made by client.
    3) in referencable method create a Refrence object.(Reference is a api class).This Reference object can be created to contain a lot of info about the remote obj u have registered. In that u can say the class that be used to create your client side stub.
    4).now when client does a lookup, jndi creates a stub using Reference object and sends it to client.
    5)the methods now u call gets passed on to actual machine running ur remote object

  • 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

  • In terms of scalabilty, will static method in normal java class better than

    You only have one copy of the static method in memory, but you have a few copy of the stateless session bean, plus the overhead of those session bean.So isn't static method of normal java class more scalable than stateless session bean.

    Then you have to take care of transaction management, connection pooling, etc other ejb services all by your self.
    In fact stateless session beans acts more like a static class. They do not get destroyed when remove() method is called on client stub. Similarly they are not always gets created whenever someone calls create() method on home interface!! (Again it's specific to appserver implementation)
    Thx.

  • Can anyone help i want to call java class using visual basic

    I want to call java class using visual basic and send some arguments to the main class

    Hi,
    I don't know VB, but you can surely launch a command line like :
    javaw.exe mypackage.MyMainClass myArgument1
    Regards

  • Can not locate Java class using JNI within C++ DLL

    I am using trying to use JNI to call a Java class from C++. The Java class uses JMS to send messages to a JMS message queue. At first I coded the C++ in a console application that created the JavaVM and used JNI to access the Java class. All worked fine. Then I called the Java class using JNI from threads and ran into the problem of the Java class not able to locate the JMS related classes. This was solved by placing the following line in the constructor of the Java class.
    Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
    Then I moved the JNI code from a console application to a DLL in specific an extension DLL that is called by SQL Server or Oracle server. The DLL will use JNI to call the Java class and send messages to a JMS message queue.
    The problem I am having now when the DLL code is called by SQL Server the call to
    JNI_CreateJavaVM
    appears to work correctly but the call to find the Java class using
    jvmEnv->FindClass(pName)
    fails. It appears the is a class loading problem which occurs due to the fact JNI is called from a DLL. When the VM is created I pass the class path information using the statement
    -Djava.class.path=
    And as I stated before it all works when running from a console application. I am new to JNI and really need help in the form of some sample code that will solve this problem. I believe I need to somehow load the classpath information from the DLL but I can not find examples on how to do this using JNI. I have tried several ways using URLClassLoader and getSystemClassLoader from JNI and either it does not work or it crashes very badly.
    I used the following code to determine what the existing class path is and the string returns empty.
    jcls = jvmEnv->FindClass("java/lang/System");
    jmid = jvmEnv->GetStaticMethodID(jcls, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
    jstrClassPath = jvmEnv->NewStringUTF("java.class.path");
    jstr = (jstring)jvmEnv->CallStaticObjectMethod(jcls, jmid, jstrClassPath);
    m_jstr = (jstring)jvmEnv->NewGlobalRef(jstr);
    pstr = jvmEnv->GetStringUTFChars(m_jstr, 0);
    Can anyone please help with example code that will solve this problem. Thanks in advance for any help.
    Charles�

    I have determined the problem occurs when the application/component is compiled using VC 6.0. The test application was compiled using VC 7.1 and works correctly by locating the class path information. If the test application is compiled using VC 6.0 it has the same problem.
    The jvm.dll I am using is version 1.4.2.80. Currently this is not an option to compile all the applications that use JNI using VC 7.1 so can someone please tell me how to solve this problem.

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Urgent !!!!!!!!!!!! regarding CREATE JAVA CLASS USING BFILE

    We have Oracle 8.1.7 spatial database. We got to load some java classes into the database. We would like to make it as the java programs to be loaded from a client system into the oracle server. I am using CREATE DIRECTORY command to create a directory object (say suppose \\prav\loadjavaclasses\. Then using the CREATE OR REPLACE JAVA CLASS USING BFILE (object_name, 'CLASSNAME.CLASS'). This .class file is in the network identified by prav which in turn has a shared directory (full privileges) loadjavaclasses folder. Can you please help in this regard.
    Please mail me to [email protected]
    thanks in advance
    SudhaSrikanthan
    null

    use loadjava

  • Invoking a method from a java class to a jsp file

    Maybe i'm going through a very basic error, but as i've looked for in some forums and nothing found decided to post. So let's go to the problem.
    Well, i have a form in a jsp file, it's basicaly html, but as i need some select boxes populated with data from the database i decided to create some methods in java classes. This is the point.
    My method receive some attributes, like the table and colums names, the name of the select box and the HttpServletResponse object.
    So after making all the database process. The method is supposed to write the result through the out.println(); object
    It goes everything all right except that the method seems to be called first than the html code coz' my select boxes comes above the head in the begin of the page and was supposed to come in the middle.
    part of the code:
    package pacote;
    import java.packages.*
    public class Class{
    public void metodo(HttpServletResponse response, String tableName, String column name, String selectName){
    PrintWriter out = response.getWriter();
    openConnection();
    //After making the query stuff
    //caso n�o haja nada na consulta
         if(rst == null)
         out.println("N�o h� registros.");
         else{
         out.println( "<select name='" +SelectName + "' id='" +SelectName + "' class=\"input_ob\" >");
         out.println( "<option value=''>Escolha: "+objeto+"</option>");
         //fill the select body with options; A while that sweap the resultSet and use the out object to write the results          
         getSelectBody(out,rst, selectValue);
    }This method is called this way:
    <tr valign="baseline">
        <td nowrap align="right">Grupo</td>
        <jsp:useBean id="m" scope="page" class="pacote.Class" />
            <td>
              <%
              try{
                   m.metodo(response, "tabela","grupo","id_grupo);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                        %></td>I'd like to know what i'm missing here. why the answer doesn't go in the place It's supposed to go.
    any answer will be greatly apreciated

    The issue is caused because you are using the response to get the writer directly.
    The JSP has gotten the same writer, but has wrapped it in a JSPWriter class. That class has got a buffer.
    So it writes the beginning html to the JSPWriter buffer.
    You write your stuff to the response writer - gets sent to the output.
    It writes more stuff to the JSPWriter buffer, then flushes that buffer - at which point all the text written into the JSP writer now gets added to the response.
    You see how your code is coming out first?
    Solution - instead of getting the writer from the response, pass the writer into your method (maybe instead of response if you don't use response for anything else)
    public void metodo(Writer jspWriter, String tableName, String column name, String selectName){
      PrintWriter out = new PrintWriter(jspWriter);
      ...That means that you will be writing to the same writer, and the text should come out in sequence.
    Cheers,
    evnafets

  • Problems Creating a Java Class using a webservice with certificate

    hi,
    i'm developing a java class that call's a webservice that needs a certificate, i'm not used to work with java, last time was 10 years ago, so i'm having some troubles because of the certificate.
    I already add the certificate using java control panel > Security > Certificates. When testing i get the following error: IOException (java.io.IOException: subject key, Unknown key spec)
    I think I need to define the certificate in my class, but i'm having a lots of trouble with the samples that i found over the internet, nothing works and i'm running out of time.
    This is my Class
    create or replace and compile java source named "FishInfoAt" as
    import java.net.*;
    import java.io.*;
    import java.security.*;
    public class FishInfoAt
         public FishInfoAt()
         public static String send(String urlfishinfoat, String mensagem, String mensagem1, String mensagem2, String mensagem3)
              // Init
              String response = "";
              String msgtotal = mensagem+mensagem1+mensagem2+mensagem3;
              String a = "";
              HttpURLConnection conn = null;
              try{
                   URL url = new URL(urlfishinfoat);
                   conn = (HttpURLConnection) url.openConnection();
                   conn.setRequestMethod("POST");
                   conn.setRequestProperty("Content-type", "text/xml; charset=utf-8");
                   conn.setRequestProperty("SOAPAction", "https://servicos.portaldasfinancas.gov.pt:401/sgdtws/documentosTransporte/");
                   conn.setRequestProperty("Content-Length","" + msgtotal.length());
                   conn.setDoOutput(true);
                   conn.setDoInput(true);
                   conn.connect();
                   OutputStream out = conn.getOutputStream();
                   out.write(msgtotal.getBytes());
                   out.flush();
                   InputStream in = conn.getInputStream();
                   int value;
                   while( (value = in.read()) != -1)
                        response+=(char)value;
              catch(Exception e)
    response = ("*** ERROR - IOException (" + e.getMessage() + a + ")");
    return response;
    /

    Hi Deepak,
    Could you please let us know upto which line your code is going safe. Try printing the value in the structure before you send that to the method GetUGEntity().
    I am not too sure that would be a problem. But I have faced a problem like this, wherein I tried to access a structure for which I have not allocated memory and hence got exception because of that.
    Since your JNI code seems to be error free, I got doubt on your C part. Sorry.
    Dhamo.

  • How to Transport Java Classes used in Mapping?

    Hi XI experts,
    Within the development of one message mapping, some external  java classes are imported and used in my UDF(user defined function). My question is: how will these external java classes be transported to the QA/PRD system? If I choose to use the file system transport method, do I have to manually find these jar files and transport them separately?
    Any comments or suggestions are highly appreciated.
    Thanks in advance
    Luis

    Hi Luis,
    Normally Mapping programs and External Jars are used in XI using Imported Archive. So this Imported archive once activated will become part of your SWCV and can be transported automatically with the SWCV.
    You dont have to worry about transporting it seperately, it will be avilable once you transport your SWCV using File system transport.
    Hope this helps,
    Regards,
    Ananth

  • Java class uses another class in a Jar file (How do I make Java see it)?

    I am trying to figure out how do I make Javac see the thinlet.class in the thinlet.jar.
    I have developed an XUL xml interface and a java program that calls the interface shown below:
    //package thinlet.demo;
    import thinlet.*;
    public class UI extends Thinlet
    { public UI () throws Exception {add(parse("UI.xml"));}
    public static void main(String[] args) throws Exception
    { new FrameLauncher("UI", new UI(), 600, 600); }}
    when I do the normal compile, I get an error:
    UI.java:4: cannot find symbol
    symbol: class Thinlet
    public class UI extends Thinlet {
    ^
    UI.java:7: cannot find symbol
    symbol : method parse(java.lang.String)
    location: class thinlet.demo.UI
    add(parse("UI.xml"));
    ^
    UI.java:12: cannot find symbol
    symbol : class FrameLauncher
    location: class thinlet.demo.UI
    new FrameLauncher("UI", new UI(), 600, 600);
    ^
    3 errors
    This thinlet class should be in the thinlet.jar that I have added the directory to the path, the directory and jarfile name to the System CLASSPATH and it couldn't see it. So finally I tried putting the thinlet.jar in the same directory to no avail. I've searched the web for some time an cannot find anything that specifically speaks to compiling a program that has parent classes in a Jar.
    Any help is definitely appreciated.

    This thinlet class should be in the thinlet.jar that I have added the directory to the path, the directory and jarfile name to the System CLASSPATH and it couldn't see it. So finally I tried putting the thinlet.jar in the same directory to no avail. I've searched the web for some time an cannot find anything that specifically speaks to compiling a program that has parent classes in a Jar.
    Any help is definitely appreciated.You just still haven't provided the jar in the classpath, or you're not using the right class name. Is the class really named thinlet.Thinlet? Or are you thinking "import thinlet.*" means to import all classes in a jar named thinlet.jar? Because the latter is not true. You need to import classes, not jar file names.

  • Call a method/Functio in a class using MouseOver StaticText - Please help!!

    Hello, I have an array of unknown size of Static Text component's of the type com.sun.rave.web.ui.component.StaticText, They're named "st_utp_1", "st_utp_2", "st_utp_3".... so forth.
    I have a class called "Page1.class" in this class I have a Method(or function, please correct me on that). called declared as:
    public void utp(int utv) {
    }When I mouse over a particular StaticText box, I would like it to call the method "utp(x);" where x is the last number in the StaticText ID. for example, If I mouseOver "st_utp_23" I would like it to call the method "utp(23);", If I then mouseOver "st_utp_107" I would like to call the method as "utp(107);".
    Currently I can't get any StaticText to call any method in my class file with a mouseOver function. I can however call my method successfully from within the class file itself.
    Please, can anyone help me?
    Looking forward to the response. Cheers

    Cheers, thanks for the quick response
    I imagine you mean something like this
    public void init() {
          st_utp_1.addMouseListener(new MouseAdapter() {
              public void mouseEntered(MouseEvent e) {
                  utptab(1);
    }The problem is that the statiicText componet "st_utp_1" is of type "com.sun.rave.web.ui.component.StaticText"
    It comes up with the error:
    symbol : method addMouseListener(<anonymous java.awt.event.MouseAdapter>)
    location: class com.sun.rave.web.ui.component.StaticText
    st_utp_1.addMouseListener(new MouseAdapter()
    If I create a new Jlabel called "jl_utp_1" and write the same code:
    public void init() {
          jl_utp_1.addMouseListener(new MouseAdapter() {
              public void mouseEntered(MouseEvent e) {
                  utptab(1);
    }it executes without a problem, I believe it's the type of StaticText compnent I'm using.
    Any more help would be appreciated.

  • Problems calling java classe using WSIF in BPEL 10.1.3.3

    Hi,
    I am working on a POC for a telecom gaint in Sweden. One of their requirement is to invoke java library.
    Inorder to do it, I have followed the below steps:
    1. Wrote a wrapper java code to a class in this library.(Attached with this mail)
    2. Using JDEV 10.1.3.3 created a wsdl file of WSIF binding type for invoking this wrapper class.(Attached with this mail.)
    3. Created the required fascade classes using the SCHEMAC option in command prompt.
    4. Placed all the class files including the wrapper class file in %BPELHOME%\bpel\system\classes
    5. Created a BPEL process to invoke the wsif wsdl.
    However while Invoking the BPEL process I am getting the error"com.collaxa.cube.ws.wsif.providers.java.WSIFOperation_Java@9ecad : Could not invoke 'authenticate'; nested exception is:
         org.collaxa.thirdparty.apache.wsif.WSIFException: No method named 'authenticate' found that match the parts specified"
    Can someone tell me how to resolve this issue.
    I have to do a presentation on this in 2 days.
    Thanks for the help.
    Regards,
    Gautham

    Hi in BPEL XML,
    Enter the credientials,
    I have pasted the Sample BPEL file.
    <?xml version="1.0"?>
    <BPELSuitcase>
         <BPELProcess id="BankTransferFlow" src="BankTransferFlow.bpel">
              <partnerLinkBindings>
                   <partnerLinkBinding name="client">
                        <property name="wsdlLocation">BankTransferFlow.wsdl</property>
                   </partnerLinkBinding>
                   <partnerLinkBinding name="bankTransfer">
                        <property name="wsdlLocation">BankTransferServiceDesign.wsdl</property>
                        <property name="wsdlRuntimeLocation">BankTransferService.wsdl</property>
                        <property name="java.naming.security.principal">oc4jadmin</property>
                        <property name="java.naming.security.credentials">welcome1</property>     
                        <property name="dedicated.connection">true</property>          
                   </partnerLinkBinding>
              </partnerLinkBindings>
    <configurations>
    <property name="testIntroduction"><![CDATA[
         This demo showcases the integration of session beans into
         an end-to-end business process. The database has 2 accounts 11111 and 22222 and both of them have initial balance 1000.
         ]]></property>
    <property name="defaultInput"><![CDATA[<BankTransferFlowRequest xmlns="http://samples.otn.com">
    <fromAccount>11111</fromAccount>
    <toAccount>22222</toAccount>
    <amount>10</amount>
    </BankTransferFlowRequest>
    ]]></property>
    <property name="transaction">participate</property>
    <property name="inMemoryOptimization">true</property>
    </configurations>          
         </BPELProcess>
    </BPELSuitcase>
    Thank you,
    [email protected]

  • Run java class using JBuilder

    hi,
    I already import the java class forder to the src folder in JBuilder where the src folder is created by the JBuilder itself. When i run compile the program there is an error in reading the java class file but when i run the program in Textpad, the program is success. May i know why? how can i run my program using java class in JBuilder instead of Java source? Thanks.

    In JBuilder there is an option of specifying what the 'main' file in a project is . Specify that to this class file
    [ What I mean is , in many java files we can define 'main' method , but we will intend to execute the main of one file only for a project . In JBuilder specify this file as the main class file ]

Maybe you are looking for

  • bi:QUERY value= dynamic in the WAD.    How to do it ?

    Hello, I need to define the query name somehow when the WAD is executed. We have one common web template for all of our queries and that is why I need to dinamicaly say in the WAD code that if the query tech is ZTEST then the real value should be ZTE

  • Single Excise Invoice for Multiple GR (background)

    We are using doing GR in background using TSW. We need to capture the Excise Invoice in J1IEX. Can we capture multiple GRs for a single Excise Invoice in this case.

  • Where on the apple site can I buy a spare mains cable for my new macbook air?

    the site is really confusing been searhcing for 10 mins now can anyoe post a link for me? regards Chris

  • Reg payment as per usage decision

    Dear all, please give advice regarding the 3 scenarios scenario 1.:    Sent material for subcontracter for making 10 materials , stock received 10 numbers out of which in usage decision we have put 8 in unrestricted and 2 in block, during invoice in

  • IPhoto 6 Rebuilding Thumbnails

    I recently upgraded from iPhoto 5 to 6, and since then, 3 times in the past week iPhoto has told me that it needs to rebuild my thumbnails. This takes about 10 minutes, so it's really getting on my nerves. Is anyone else having this problem or know h