Xindice/XUpdate problems

Hello,
I have the following XML document stored in Xindice
<order num="O3634">
     <customer>
          bill gates
     </customer>
     <products>
          <product pid="P3245">
               Linux
          </product>
     </products>
</order>I am using xmldb apis to attempt to update a text node.
Here's is my modifications document
<xupdate:modifications version="1.0" xmlns:xupdate="http://www.xmldb.org/xupdate">
     <xupdate:update select="/order/products/product[@pid='P3245']">THE WORLD</xupdate:update>
</xupdate:modifications>When i do:
    XUpdateQueryService srvc =
        (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
     srvc.update(xupdate);It throws exceptions:
Query Processing Error
org.xmldb.api.base.XMLDBException: Query Processing Error
     at org.apache.xindice.core.FaultCodes.createXMLDBException(FaultCodes.java:239)
     at org.apache.xindice.client.xmldb.services.XUpdateQueryServiceImpl.updateResult(XUpdateQueryServiceImpl.java:170)
     at org.apache.xindice.client.xmldb.services.XUpdateQueryServiceImpl.update(XUpdateQueryServiceImpl.java:185)
     at Proggy.doUpdate(Proggy.java:64)
     at Proggy.main(Proggy.java:22)I can do queries against the xmldb just fine. Any ideas?

Here's the code sample if anyone cares:
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
public class Proggy
  public static void main( String[] args ) throws Exception
    Collection col = null;
    try
      String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
      Class c = Class.forName( driver );
      Database db = (Database) c.newInstance();
      DatabaseManager.registerDatabase( db );
      col = DatabaseManager.getCollection( "xmldb:xindice:///db/sample" );
      doQuery( col );
      doUpdate( col );
      doQuery( col );
    catch (Exception e)
      System.out.println( e.getMessage());
      e.printStackTrace();
    finally
      if (col != null)
        col.close();
  public static void doQuery( Collection col ) throws Exception
    String xpath = "/order/products/product";
    XPathQueryService srvc = (XPathQueryService)col.getService( "XPathQueryService", "1.0" );
    ResourceSet resultSet = srvc.query(xpath);
    ResourceIterator results = resultSet.getIterator();
    while (results.hasMoreResources())
      Resource res = results.nextResource();
      Object o = res.getContent();
      System.out.println( o.getClass().getName());
      System.out.println( o );
  public static void doUpdate( Collection col ) throws Exception
    String xupdate =
        "<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\">\n" +
        "\t<xupdate:update select=\"/order/products/product[@pid='P3245']\">THE WORLD</xupdate:update>\n" +
        "</xupdate:modifications>\n";
    System.out.println( xupdate );
    XUpdateQueryService srvc =
        (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
     srvc.update(xupdate);
}The doQuery function works fine
the doUpdate function throws the exception on
<srvc.update(xupdate);>

Similar Messages

  • Xindice - XPath Problem

    Hello,
    I've been using Xindice DB to manage XML files. Everything seemed to work well, but then i've run in some problems concering XPath queries.
    I have two "resources" (item1 and item2) for testing purposes in a collection named items. Both xml resources look like the following:
    <?xml version="1.0" encoding="UTF-8"?>
    <assessmentItemType title="item1" timeDependent="false"
      identifier="item1" adaptive="false"
      xmlns:ns2="http://www.imsglobal.org/xsd/imslip_v1p0"
      xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
      xmlns:ns4="http://www.w3.org/1998/Math/MathML"
      xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns5="http://www.w3.org/2001/XInclude">
      <itemBody id="itemBody1"/>
    </assessmentItemType>i (e.g.) want to get the id of the itemBody element, so i use the xpath query
    //itemBody/@id For a strange reason i don't get any results back.
    (I tested the query with the xpath trainer on http://www.write4food.orangegear.com/xptr.html to check if my xpath query was wrong, but it wasn't)
    If i just use
    /* as an xpath query, i get both resources (item1 and item2), which means that some xpath queries work.
    I'm fetching the data with the following code
    String query = "//itemBody/@id";
    XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
    ResourceSet resultSet = service.query(query);
    ResourceIterator results = resultSet.getIterator();
    while (results.hasMoreResources()) {
         Resource res = results.nextResource();
         System.out.println((String) res.getContent());
    }Has anyone an explanation for this behavior?
    Thanks in advance!
    Figured it out: Forgot to add the namespaces information. Now everything works fine...
    XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
    service.setNamespace("ns-prefix", "ns-url");n10e
    Message was edited by:
    n10e

    Create a DocumentFragment node from the Xml node to unmarshall.
    Unmarshall document node with method unmarshal(org.w3c.dom.Node node)
    Document document;
    Node node;//Node to unmarshall
    DocumentFragment df=
    document.createDocumentFragment();
    df.appendChild(node);
    JAXBContext jc = JAXBContext.newInstance("");
    Unmarshaller u = jc.createUnmarshaller();
    u.unmarshal(df);

  • Xindice problems...

    I have been plowing through the WSDP tutorial this afternoon and I am having problem running xindice. This problem has two parts which I must explain before stating what my problem. After running starting the tomcat server, I tried running running the xindice-startup batch file (on Windows 2000) as the tutorial indicates. I got an error stating the following:
    [java] javax.xml.parsers.FactoryConfigurationError: java.lang.ClassNotFound
    Exception: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
    [java] at javax.xml.parsers.DocumentBuilderFactory.newInstance(Document
    BuilderFactory.java:149)
    [java] at org.apache.xindice.server.Kernel.<init>(Unknown Source)
    [java] at org.apache.xindice.server.Xindice.main(Unknown Source)
    [java] Exception in thread "main"
    [java] Java Result: 1
    BUILD SUCCESSFUL
    I never really resolved the issue. I managed to get the xindice database running by mapping the commands in the xindice.xml file to the command prompt. The commandline ended up as follows:
    java -Xms16m -Dxindice.home=C:\jwsdp-1_0-ea1\tools\xindice -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl org.apache.xindice.server.Xindice
    My classpath contains all the jar files located in directories c:\jwsdp-1_0-ea1\common\lib and c:\jwsdp-1_0-ea1\tools\xindice\java\lib. The database seemingly runs fine. I get the following output:
    Xindice 1.0rc1 (DarkHorse)
    Database: 'db' initializing
    Script: 'GET' added to script storage
    Service: 'db' started
    Service: 'GopherServer' started @ gopher://FlatBug:4070/
    Service: 'HTTPServer' started @ http://FlatBug:4080/
    Service: 'APIService' started
    Server Running
    When I tried running indri to test the xindice database, I get the following error:
    ERROR: org.xmldb.api.base.XMLDBException while connecting: A connection to the Database instance 'db' could not be created. Error: http://localhost:4080/db_boot
    strap.ior
    error in storing document: failed to initialize DB: aborting connection attempt.
    java.lang.RuntimeException: failed to initialize DB: aborting connection attempt
    Does anyone have any ideas why I would be getting this exception? Is this error related somehow to the problem I am having running the xindice-start.bat file?
    One thing that puzzles me is that a couple of my co-workers have been able to execute these commands without any problems on their machines. Any help would greatly be appreciated.
    -Kyle

    Thank you for your suggestions. I managed to fix the problem, in part by your suggestions. When I tried to connect to the database server through a Web browser, the displayed page mentioned an error stating that docs/index.html was not found. Upon closer inspection of the xindice.xml file, I realized that ../tools/xindice is specified as the working directory. I applied the changes to my custom batch file. I can now run the Indri tool without any problems. Thank you again for your suggestions.
    I still don't know why I am not able to run the provided xindice_start batch file. I tried reinstalling jwsdp, but that didn't solve the problem. If you have any suggestions, I would greatly appreciate hearing them. As for now, I am perfectly content with knowing that my xindice database is up and running. Thank you.

  • Problem with Connection Pooling of datasources in a web service

    Hi,
    I have been driven insane trying to fix this problem, I am trying to connect to a MS SQL data source from a web service in tomcat 4.1, so I have defined the data source through tomcats server administration pages and checked that it has inserted the correct code to server.xml. I have also added the relevant information to the web.xml and added the code to the service. when I start tomcat it outputs:
    DbcpDataSourceFactory: driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver, url=jdbc:microsoft:sqlserver://192.168.0.22:1433:databaseName=dbname, user=sa
    but then these errors occours:
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke
    (DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
    Caused by: java.lang.IllegalStateException: Context path /RegistryServer is already in use
    at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:523)
    ... 42 more
    and
    [ERROR] Digester - -End event threw exception <java.lang.reflect.InvocationTargetException>
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
         at org.apache.commons.digester.SetNextRule.end
    (Bootstrap.java:203)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
    Caused by: java.lang.IllegalStateException: Context path /Xindice is already in use
         at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:523)
         ... 42 more
    And when I try to use the data source my code gets the context but when getting the datasource it shows the error:
    Error doing something: javax.naming.NamingException: DbcpDataSourceFactory: driverClassName is required
    My server.xml reads:
    <Resource name="jdbc/msService" scope="Shareable" type="javax.sql.DataSource"/>
    <ResourceParams name="UserDatabase">
    <parameter>
    <name>factory</name>
    <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
    </parameter>
    <parameter>
    <name>pathname</name>
    <value>conf/tomcat-users.xml</value>
    </parameter>
    </ResourceParams>
    <ResourceParams name="jdbc/msService">
    <parameter>
    <name>validationQuery</name>
    <value></value>
    </parameter>
    <parameter>
    <name>user</name>
    <value>sa</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:microsoft:sqlserver://192.168.0.22:1433:databaseName=dbname</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>password</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>4</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    </ResourceParams>
    and my web.xml
    <web-app>
    <display-name>User Service</display-name>
    <description>A service to perform user information orientated tasks</description>
    <session-config>
    <session-timeout>60</session-timeout>
    </session-config>
    <resource-ref>
    <description> Resource reference to java.sql.Connection factory defined in server.xml</description>
    <res-ref-name>jdbc/msService</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
    I have read the other posts regarding this error and most mention that the jar files need to be in <root>/common/lib but I have deinitely put all the MS jar files here!!!
    sorry this is such a long post but if any one has any idea it would be most appreciated!!!!
    cheers
    pasty

    Hi,
    I'm struggling with the same problem. One thing I noticed is that your url looks a bit different than others that I've seen:
    Yours:
    url=jdbc:microsoft:sqlserver://192.168.0.22:1433:databaeName=dbname, user=sa
    Most other folks:
    url=jdbc:microsoft:sqlserver://192.168.0.22:1433;databaseName=dbname; user=sa
    Note the semicolons.
    I don't know whether this will help you or not, but it's worth a try.
    Does anyone know where I can get documentation for the options that MS' jdbc driver for SQL Server? I've googled groups and the web and can't find anything authoritative.
    Dan
    Hi,
    I have been driven insane trying to fix this problem,
    I am trying to connect to a MS SQL data source from a
    web service in tomcat 4.1, so I have defined the data
    source through tomcats server administration pages and
    checked that it has inserted the correct code to
    server.xml. I have also added the relevant
    information to the web.xml and added the code to the
    service. when I start tomcat it outputs:
    DbcpDataSourceFactory:
    driverClassName=com.microsoft.jdbc.sqlserver.SQLServer
    river,
    url=jdbc:microsoft:sqlserver://192.168.0.22:1433:databa
    eName=dbname, user=sa
    but then these errors occours:
    java.lang.reflect.InvocationTargetException
    at
    at
    at
    t sun.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)
    at
    at
    at
    t
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMetho
    AccessorImpl.java:39)
    at
    at
    at sun.reflect.DelegatingMethodAccessorImpl.invoke
    (DelegatingMethodAccessorImpl.java:25)
    at
    at
    at java.lang.reflect.Method.invoke(Method.java:324)
    at
    at
    at
    t
    org.apache.commons.launcher.ChildMain.run(ChildMain.jav
    :269)
    Caused by: java.lang.IllegalStateException: Context
    path /RegistryServer is already in use
    at
    at
    at
    t
    org.apache.catalina.core.StandardHostDeployer.addChild(
    tandardHostDeployer.java:523)
    ... 42 more
    and
    [ERROR] Digester - -End event threw exception
    <java.lang.reflect.InvocationTargetException>
    java.lang.reflect.InvocationTargetException
    at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMeth
    dAccessorImpl.java:39)
    at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Delega
    ingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
    at
    org.apache.commons.beanutils.MethodUtils.invokeMethod(
    ethodUtils.java:216)
         at org.apache.commons.digester.SetNextRule.end
    (Bootstrap.java:203)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMeth
    dAccessorImpl.java:39)
    at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Delega
    ingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
    at
    org.apache.commons.launcher.ChildMain.run(ChildMain.ja
    a:269)
    Caused by: java.lang.IllegalStateException: Context
    path /Xindice is already in use
    at
    org.apache.catalina.core.StandardHostDeployer.addChild
    StandardHostDeployer.java:523)
         ... 42 more
    And when I try to use the data source my code gets the
    context but when getting the datasource it shows the
    error:
    Error doing something: javax.naming.NamingException:
    DbcpDataSourceFactory: driverClassName is required
    My server.xml reads:
    <Resource name="jdbc/msService" scope="Shareable"
    le" type="javax.sql.DataSource"/>
    <ResourceParams name="UserDatabase">
    <parameter>
    <name>factory</name>
    <value>org.apache.catalina.users.MemoryUserDatabaseFac
    ory</value>
    </parameter>
    <parameter>
    <name>pathname</name>
    <value>conf/tomcat-users.xml</value>
    </parameter>
    </ResourceParams>
    <ResourceParams name="jdbc/msService">
    <parameter>
    <name>validationQuery</name>
    <value></value>
    </parameter>
    <parameter>
    <name>user</name>
    <value>sa</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:microsoft:sqlserver://192.168.0.22:1433:da
    abaseName=dbname</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>password</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>4</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</v>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    </ResourceParams>
    and my web.xml
    <web-app>
    <display-name>User Service</display-name>
    <description>A service to perform user information
    n orientated tasks</description>
    <session-config>
    <session-timeout>60</session-timeout>
    </session-config>
    <resource-ref>
    <description> Resource reference to
    to java.sql.Connection factory defined in
    server.xml</description>
    <res-ref-name>jdbc/msService</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
    I have read the other posts regarding this error and
    most mention that the jar files need to be in
    <root>/common/lib but I have deinitely put all the MS
    jar files here!!!
    sorry this is such a long post but if any one has any
    idea it would be most appreciated!!!!
    cheers
    pasty

  • Problems accessing Web service from registry server

    "Hi,
    While trying to develop a dynamic webservice, I encounter some problems.
    The details are as follows:
    I develop a webservice with following interfaces and implementation
    classes:
    Interface : pricequote.IPriceQuote
    Implementation : pricequote.PriceQuoteImpl
    The service does get registered on the XINDICE registry server. ( I am
    using JWSDP to develop the above), and also is deployed on the tomcat
    server.
    I have specified the following path for the service end point:
    http://localhost:8080/PriceQuoteService/pricequote/IPriceQuote
    But when I call the sayHello(String strName) method, I get the following
    error:
    [java] java.rmi.RemoteException: cannot connect to server: /PriceQuoteServi
    ce/pricequote/IPriceQuote; nested exception is:
    [java] cannot connect to server: /PriceQuoteService/pricequote/IPriceQu
    ote
    [java] at pricequote.IPriceQuote_Stub.sayHello(IPriceQuote_Stub.java:76
    [java] at pricequote.PriceQuoteClient.getData(Unknown Source)
    [java] at pricequote.PriceQuoteClient.main(Unknown Source)
    [java] Caused by: cannot connect to server: /PriceQuoteService/pricequote/I
    PriceQuote
    [java] at com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpCl
    ientTransport.java:119)
    [java] at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.
    java:73)
    [java] at pricequote.IPriceQuote_Stub.sayHello(IPriceQuote_Stub.java:59
    [java] ... 2 more
    BUILD SUCCESSFUL
    Total time: 3 seconds

    No..
    Not able to to open the WSDL either..Getting HTTP status 404..
    The location http://localhost:8080/PriceQuoteService does open, though it doesnt't have any web pages. The organization data is accessible from registry-server also.
    ---Original Message----
    are you able to access this endpoint through a browser
    what happens when you do
    http://localhost:8080/PriceQuoteService/pricequote/IPri
    eQuote?WSDL
    using IE ? do you see the WSDL in your IE window ?
    Do you see the port info getting populate under the
    service section at the base of the WSDL ?

  • Not able to start xindice data base

    I am trying to go through the tutorial of registry server. But, I am not able to start xindice database. Following is the exception that I am getting,Buildfile: d:\JWSDP-~1\bin\xindice.xml
    start:
    [java]
    [java] Xindice 1.0rc1 (DarkHorse)
    [java]
    [java] Database: 'db' initializing
    [java] java.lang.NoSuchMethodError
    [java] at org.apache.xindice.xml.dom.DOMParser.getSAXParser(Unknown Sou
    rce)
    [java] at org.apache.xindice.xml.dom.DOMParser.<init>(Unknown Source)
    [java] at org.apache.xindice.xml.dom.DOMParser.toDocument(Unknown Sourc
    e)
    [java] at org.apache.xindice.core.SystemCollection.init(Unknown Source)
    [java] at org.apache.xindice.core.Database.setConfig(Unknown Source)
    [java] at org.apache.xindice.server.services.XindiceService.initialize(
    Unknown Source)
    [java] at org.apache.xindice.server.standard.StdServiceManager.addServi
    ce(Unknown Source)
    [java] at org.apache.xindice.server.standard.StdServiceManager$1.proces
    s(Unknown Source)
    [java] at org.apache.xindice.util.Configuration.processChildren(Unknown
    Source)
    [java] at org.apache.xindice.server.standard.StdServiceManager.setConfi
    g(Unknown Source)
    [java] at org.apache.xindice.server.Kernel.loadAPI(Unknown Source)
    [java] at org.apache.xindice.server.Kernel.<init>(Unknown Source)
    [java] at org.apache.xindice.server.Xindice.main(Unknown Source)
    [java] Exception in thread "main"
    [java] Java Result: 1
    BUILD SUCCESSFUL
    does any one have any idea about this???
    Pawan

    A common source of problems like this is putting
    jaxp.jar or crimson.jar into the Java system
    extensions directory ($JAVA_HOME/jre/lib/ext),
    where it always overrides whatever is supplied in
    common/lib.
    So I need you to go into your $JAVA_HOME/jre/lib/ext
    and make sure you do not have any copies of
    crimson or jaxp present there. If you do have them
    there, i want you to move them to a seperate dir.
    And then try the whole thing all over again.
    amlan

  • Problem in running example in web service tutorial

    Hi,
    I have installed jwsdp 1.1. When I followed the procedures stated in the tutorial and compiled the example in the dir
    {jwsdp home}\docs\tutorial\examples\cb\jaxm\, errors occur.
    Here are the errors occurs in the launcher.server.log.
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
         at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:260)
         at org.apache.commons.digester.Digester.endElement(Digester.java:830)
         at org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:552)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1071)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1533)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:346)
         at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:529)
         at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:585)
         at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
         at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1142)
         at org.apache.commons.digester.Digester.parse(Digester.java:1302)
         at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:335)
         at org.apache.catalina.core.StandardHost.install(StandardHost.java:804)
         at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:452)
         at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:409)
         at org.apache.catalina.startup.HostConfig.start(HostConfig.java:882)
         at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:368)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1198)
         at org.apache.catalina.core.StandardHost.start(StandardHost.java:739)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1190)
         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
         at org.apache.catalina.core.StandardService.start(StandardService.java:499)
         at org.apache.catalina.core.StandardServer.start(StandardServer.java:2187)
         at org.apache.catalina.startup.Catalina.start(Catalina.java:504)
         at org.apache.catalina.startup.Catalina.execute(Catalina.java:399)
         at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
    Caused by: java.lang.IllegalStateException: Context path /RegistryServer is already in use
         at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:523)
         ... 42 more
    [ERROR] Digester - -End event threw exception <java.lang.reflect.InvocationTargetException>
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
         at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:260)
         at org.apache.commons.digester.Digester.endElement(Digester.java:830)
         at org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:552)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1071)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1533)
         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:346)
         at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:529)
         at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:585)
         at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
         at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1142)
         at org.apache.commons.digester.Digester.parse(Digester.java:1302)
         at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:335)
         at org.apache.catalina.core.StandardHost.install(StandardHost.java:804)
         at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:452)
         at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:409)
         at org.apache.catalina.startup.HostConfig.start(HostConfig.java:882)
         at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:368)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:166)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1198)
         at org.apache.catalina.core.StandardHost.start(StandardHost.java:739)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1190)
         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
         at org.apache.catalina.core.StandardService.start(StandardService.java:499)
         at org.apache.catalina.core.StandardServer.start(StandardServer.java:2187)
         at org.apache.catalina.startup.Catalina.start(Catalina.java:504)
         at org.apache.catalina.startup.Catalina.execute(Catalina.java:399)
         at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
    Caused by: java.lang.IllegalStateException: Context path /Xindice is already in use
         at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:523)
         ... 42 more
    [ERROR] Digester - -End event threw exception <java.lang.reflect.InvocationTargetException>
    Sorry for posting such a long error capturing above.
    But I really don't know which part goes wrong. I have already copied the endorse dir to my java sdk 1.4.1 home.
    Any ideas?
    A million thanks in advance ^^
    Sherina

    I have this problem too. Please let me know if you have resolved it.

  • No response from Xindice when browsing to localhost

    Hi there,
    I have been using the JWSDP for my xml development and now want to explore the use of the Xindice xml database that conviniently comes installed with the JWSDP. Searched the forums, but no one else seems to have this particular response/problem.
    When I click on "start Xindice" from my start menu (in Win 98SE), the Java pop up box for the Xindice server displays but when using my browser to go to http://localhost:4080, I get an error saying "the requested URL could not be retrieved"
    Why does this happen? Shouldnt everything be ready to go "out of the box"? I cant find any info on on Xindice in the WSDP Tutorial either.
    Any advice/direction is much appreciated.
    Thnks

    Hello,
    http://xml.apache.org/xindice/
    and strongly recommended
    http://www.ifs.tuwien.ac.at/~aschatt/software/xindice_browser/xindice_browser.html

  • Eternal problem: NAMESPACE_ERR

    Hi all,
    I know I'm not the only one to have this problem, and I've seen some people solving this with one single call to setNamespaceAware, but somehow I must be doing something wrong cos it doesn't work for me.
    Basically, I want to import namespace'd nodes into a new DOM structure, and I get the usual error:
    Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
    Here's how I do it: I have a Xindice DB, which I access using the XML:DB API. I then do an XPath query using the XPathQueryService::query function, which returns a ResultSet. My goal is to turn the array of nodes contained in this ResultSet into a single XML structure (org.w3c.dom.Document).
    The entries as returned by the call to the query function look like this:
    <#document>
      <termEntry src:col="/db/test" src:key="entry5" xmlns="http://www.lisa.org/tbx" xmlns:src="http://xml.apache.org/xindice/Query">
        <!-- content here... -->
      </termEntry>
    </#document>I create a DOM structure as follows:
    Node[]                    result; // the ResultSet returned by the query function is converted into an array of org.w3c.dom.Node's
    DocumentBuilderFactory          dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware( true );
    DocumentBuilder               docbuilder = dbf.newDocumentBuilder();
    Document               doc = docbuilder.newDocument();
    Element                    response = doc.createElement( "termdb-response" );
    doc.appendChild( response );
    for( int i = 0 ; i < result.length ; i++ ) {
         response.appendChild( doc.importNode( result[ i ].getFirstChild(), true ) );   // **** error here ****
    When this is executed, I get the error named above on the line indicated. As I said, some people seem to have solved the problem by making the DocumentBuilderFactory namespace aware, but I've tried that and it hasn't changed anything. I guess it's very stupid, but could someone please tell me how I can import these nodes into my structure??
    Thanks a lot in advance!
    pagod

    hi,
    thx for the reply.
    i didn't parse the document. it was imported first into the Xindice database (using Xindice itself, no API), and now i'm retrieving it using an XPathQueryService (i.e. using an XPath expression that's matched agains the Xindice DB). The namespace was declared in the original document that was imported into Xindice, and is required for the XPath expression to match.
    The result of the query is a so-called ResultSet, which is nothing more than an array of so-called Resource's, which can be cast into XMLResource's (org.xmldb.api.modules.XMLResource). This XMLResource provides a function "getContentAsDOM", which returns a w3c DOM structure (document) as shown in my first post.
    upon calling function getNamespaceURI on the first child of that structure, i get the proper namespace -- i.e. http://www.lisa.org/tbx , which is correct
    in the meanwhile, i've tried declaring the root of my new structure with the proper namespace as well:
    Element response = doc.createElementNS( "http://www.lisa.org/tbx", "termdb-response" );this makes the tbx namespace the default namespace for my newly-created document. however, this hasn't changed anything to the namespace problem when importing the nodes :-|
    i've tried using adoptNode as well, but it simply and quietly returns null...
    pagod

  • Dbms or xindice

    I have a project idea in which I wish to handle hierarchical data. My project is such that every thing regarding the data ( i.e hierarchy ) will be obtained at the runtime and the program is supposed to handle the same.
    which way should i choose, the mysql or should i go for some real hierarchical data handling using the apache tools i.e xindice, xerces etc.
    confused and need some direction.

    Depends on the details.
    Some problem domain spaces are such that a significant amount of the real storage is best done using OO type persistance. (Myself I have only heard, not seen, of one to which this actually is applicable.)
    OO databases are universally slower with database type operations that operate on large amounts of data.
    You are stating that you have already identified that the first is what you need. So only the second matters. If there is low volume then the second will not matter.

  • A problem with threads

    I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
    Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
    My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
    Thank you in advance,
    Lefty

    This was one solution from the socket programming forum, have you tried this??
    public Thread MyThread extends Thread{
         boolean active = true;          
         public void run(){
              ss.setSoTimeout(90);               
              while (active){                   
                   try{                       
                        serverSocket = ss.accept();
                   catch (SocketTimeoutException ste){
                   // do nothing                   
         // interrupt thread           
         public void deactivate(){               
              active = false;
              // you gotta sleep for a time longer than the               
              // accept() timeout to make sure that timeout is finished.               
              try{
                   sleep(91);               
              }catch (InterruptedException ie){            
              interrupt();
    }

  • A problem with Threads and MMapi

    I am tring to execute a class based on Game canvas.
    The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
    The MIDI tone "Stammers".
    How to over come the problem?
    Thanks in advance
    Kobi
    See Code example below:
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    public class MainScreenCanvas extends GameCanvas implements Runnable {
         private MainMIDlet parent;
         private boolean mTrucking = false;
         Image imgBackgound = null;
         int imgBackgoundX = 0, imgBackgoundY = 0;
         Player player;
         public MainScreenCanvas(MainMIDlet parent)
              super(true);
              this.parent = parent;
              try
                   imgBackgound = Image.createImage("/images/area03_bkg0.png");
                   imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
                   imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
              catch(Exception e)
                   System.out.println(e.getMessage());
          * starts thread
         public void start()
              mTrucking = true;
              Thread t = new Thread(this);
              t.start();
          * stops thread
         public void stop()
              mTrucking = false;
         public void play()
              try
                   InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
                   player = Manager.createPlayer(is, "audio/midi");
                   player.setLoopCount(-1);
                   player.prefetch();
                   player.start();
              catch(Exception e)
                   System.out.println(e.getMessage());
         public void run()
              Graphics g = getGraphics();
              play();
              while (true)
                   tick();
                   input();
                   render(g);
          * responsible for object movements
         private void tick()
          * response to key input
         private void input()
              int keyStates = getKeyStates();
              if ((keyStates & LEFT_PRESSED) != 0)
                   imgBackgoundX++;
                   if (imgBackgoundX > 0)
                        imgBackgoundX = 0;
              if ((keyStates & RIGHT_PRESSED) != 0)
                   imgBackgoundX--;
                   if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
                        imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
          * Responsible for the drawing
          * @param g
         private void render(Graphics g)
              g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
              this.flushGraphics();
    }

    You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
    However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
    You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
    Regds,
    SD
    N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
    Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM

  • J2ME problem with threads

    Hi all,
    I would like to ask you for a help. I need to write a small program at my university. I started to write a midlet which function would be to countdown time for sports activities. I woul like to start a new thread - the one that counts down - and at the same time make the main thread sleep. After the "countdown" thread finishes, the main thread wakes up and waits for user input. The problem is that when the "countdown" thread finishes his work, I've got Uncaught exception java/lang/NullPointerException. error and the midlet halts.
    Below you can find the code
    import java.lang.*;
    import java.util.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class intervals extends MIDlet implements CommandListener
    public Display ekran;
    private SweepCanvas sweeper;
    private Form rundy;
    private TextField round0, round1, round2, round3, round4, round5, round6, round7, round8;
    private long czas,x;
    private Command exitCommand;
    private Command addRound;
    private Command delRound;
    private Command start;
    private TextField repeat;
    private Form odliczanie;
    private Alert ostrz;
    Licznik thread;
    String test;
    StringItem test1;
    int parz,i,j,k;
    static int l;
    int ilrund;
    int ilpowt;
    Item sec;
    long sec1;
    public intervals()
        rundy = new Form("Interwa&#322;y sportowe");
        exitCommand = new Command("Wyj&#347;cie", Command.EXIT, 2);
        addRound = new Command("Dodaj","Dodaj rund&#281;", Command.ITEM,1);
        delRound = new Command("Usu&#324;","Usu&#324; ostatni&#261; rund&#281;", Command.ITEM,1);
        start = new Command("Start", Command.ITEM,1);
        odliczanie = new Form("Odliczanie");
        TextField dodaj(TextField kolej)
            kolej=new TextField("Podaj czas (s) rundy "+parz,null, 4, TextField.NUMERIC);//stworzenie nowej instancji do wybierania czasu trwania rundy
            if(rundy.size()==0)
                rundy.insert(rundy.size(),kolej);
                else
                    rundy.insert(rundy.size()-1, kolej);
            return kolej;
        void odliczanie(TextField round)
            monitor m=new monitor();
            k=Integer.parseInt(round.getString());
            ekran.setCurrent(odliczanie);
            thread=new Licznik(k,odliczanie);
            thread.start();
            ekran.setCurrent(rundy);
    public void startApp()// throws MIDletStateChangeException
        rundy.deleteAll();
        repeat = new TextField("Podaj ilo&#347;&#263; powtórze&#324;",null,1,TextField.NUMERIC);
        rundy.addCommand(addRound);
        rundy.addCommand(exitCommand);
        rundy.setCommandListener(this);
        Canvas obrazek = new MyCanvas();
        ekran = Display.getDisplay(this);
        ekran.setCurrent(obrazek);
        czas=System.currentTimeMillis();
        while (System.currentTimeMillis()<czas+1000)
            continue;
        ekran.setCurrent(rundy);
    public void pauseApp()
    public void destroyApp(boolean unconditional)
        notifyDestroyed();
    public void commandAction(Command c, Displayable s)
        if (c == exitCommand)
            destroyApp(false);
            notifyDestroyed();
        else if(c==addRound)
            if(rundy.size()==0)//Sprawdzenie ilo&#347;ci elementów w celu poprawnego wy&#347;wietlania liczby rund w formie
                parz=1;
                else
                parz=rundy.size();
            switch(parz)
                case 1:
                    round0=dodaj(round0);break;
                case 2:
                    round1=dodaj(round1);break;
                case 3:
                   round2= dodaj(round2);break;
                case 4:
                    round3=dodaj(round3);break;
                case 5:
                    round4=dodaj(round4);break;
                default:
                    ostrz=new Alert("Uwaga","Maksymalna liczba rund wynosi 9", null, AlertType.INFO);
                    ostrz.setTimeout(3000);
                    ekran.setCurrent(ostrz);
            if(rundy.size()==1)
                rundy.append(repeat);
                rundy.addCommand(start);
            rundy.addCommand(delRound);
        else if(c==delRound)
            if(rundy.size()!=0)
                rundy.delete(rundy.size()-2);
                if (rundy.size()==1)
                    rundy.deleteAll();
                if(rundy.size()==0)
                    rundy.removeCommand(delRound);
                    rundy.removeCommand(start);
        else if(c==start)
            ilrund=rundy.size()-1;
            if(this.repeat.size()>0)
                ilpowt=Integer.parseInt(this.repeat.getString());
            ekran = Display.getDisplay(this);
            for (i=1; i<=ilpowt;i++)
                odliczanie= new Form("Odliczanie");
                 for (j=0;j<ilrund;j++)
                    switch(j)
                         case 0:
                             odliczanie(round0);
                             break;
                         case 1:
                             odliczanie(round1);
                             break;
                         case 2:
                             odliczanie(round2);
                             break;
                         case 3:
                             odliczanie(round3);
                             break;
                         case 4:
                             odliczanie(round4);
                             break;
                         case 5:
                             odliczanie(round5);
                             break;
                         case 6:
                             odliczanie(round6);
                             break;
                         case 7:
                             odliczanie(round7);
                             break;
                         case 8:
                             odliczanie(round8);
                             break;
    class Licznik extends Thread
        int czas1,k;
        Form forma;
        monitor m;
        public Licznik(int k,Form formap)
            czas1=k;
            forma=formap;
        public synchronized void run()
            while(czas1>0)
                forma.deleteAll();
                forma.append("Czas pozosta&#322;y (s): "+czas1);
                try{Thread.sleep(1000);} catch(InterruptedException e){e.printStackTrace();}
                czas1--;
            if(czas1<=0)
                m.put();
        }and monitor class
    public class monitor
    boolean busy=false;
    synchronized void get()
        if(!busy)
            try
                wait();
            }catch(InterruptedException e){e.printStackTrace();}
        notify();
    synchronized void put()
        if(busy)
            try
            wait();
            }catch(InterruptedException e){e.printStackTrace();}
        busy=true;
        notify();
    }Can anybody help me with this?

    Groovemaker,
    Your Licznik class has a member m of type monitor, which has not been instantiated (in other words is null) hence, when calling m.put() you get NullPointerException. Please also mind, that using Thread.sleep(1000) is not an accurate way of measuring time.
    If I may, please use recommended for Java class naming conventions - some of your names use lower case, while other don't which is confusing to the reader.
    Daniel

  • Problem with threads within applet

    Hello,
    I got an applet, inside this applet I have a singleton, inside this singleton I have a thread.
    this thread is running in endless loop.
    he is doing something and go to sleep on and on.
    the problem is,
    when I refresh my IE6 browser I see more than 1 thread.
    for debug matter, I did the following things:
    inside the thread, sysout every time he goes to sleep.
    sysout in the singleton constructor.
    sysout in the singleton destructor.
    the output goes like this:
    when refresh the page, the singleton constructor loading but not every refresh, sometimes I see the constructor output and sometimes I dont.
    The thread inside the singleton is giving me the same output, sometime I see more than one thread at a time and sometimes I dont.
    The destructor never works (no output there).
    I don't understand what is going on.
    someone can please shed some light?
    thanks.
    btw. I am working with JRE 1.1
    this is very old and big applet and I can't convert it to something new.

    Ooops. sorry!
    I did.
         public void start() {
         public void stop() {
         public void destroy() {
              try {
                   resetAll();
                   Configuration.closeConnection();
                   QuoteItem.closeConnection();
              } finally {
                   try {
                        super.finalize();
                   } catch (Throwable e) {
                        e.printStackTrace();
         }

  • Problem with Threads and a static variable

    I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
    Code functionality:
    A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
    The problem as far I understand is:
    Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
    Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
    Thanks,
    B.D.
    Code:
    private static volatile boolean bChanged = false;
    private static Thread objMainProcess;
       protected static void Init(){
            objMainProcess = new Thread() {
                public void run() {
                    while( objMainProcess == Thread.currentThread() ) {
                       GetState();
            objMainProcess.setDaemon( true );
            objMainProcess.start();
        public static void initStatusTimer(){
            if(objTimer == null)
                 objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
                    public void actionPerformed( java.awt.event.ActionEvent evt){
                              SetState();
        private static void SetState(){
            if( objMainProcess == null ) return;
            synchronized( objMainProcess ) {
                bChanged = true;
                try{
                    objMainProcess.notify();
                }catch( IllegalMonitorStateException e ) {}
        private static boolean GetState() {
            if( objMainProcess == null ) return false;
            synchronized( objMainProcess ) {
                if( bChanged) {
                    SendMessage();
                    bChanged = false;
                    return true;
                try {
                    objMainProcess.wait();
                }catch( InterruptedException e ) {}
                return false;
        }

    Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
    Again as you said, There is a reason I can't call sendMessage() inside setState().
    The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
    Thanks,
    B.D.

Maybe you are looking for

  • Templates with in HTML files

    can I create templetes within html files e.g. all wesite buit with html and news section in templates? How can this be achieved? Thanks for your assistance!

  • Selection date : outbound delivery

    Hi , I am not sure what is the 'Selection Date' of the outbound delivery. Please could you clarify for me. Is it the date outbound delivery is created? What is there to 'select'? regards John Edited by: johntivoli on Dec 8, 2010 3:57 PM

  • How can I ensure an app will play audio even when phone is in silent mode

    Am looking at deploying a third party app, but I want to ensure that the app's built in notification system will notify on the user's iphone, even if the user has set the phone to silent mode. In the Android world <gasp!> there is an app called Criti

  • Recurring kernel panic 10.7.5 iMac

    I've been encountering irregular, but consistent kernel panics for the past three months.  I'm submitting reports, but there don't seem to be any updates in the channel that have affected the situation.  I'd like to get to the bottom of this.  The ma

  • Fonts are missing in Text Edit

    What can I do to add more font selections in Text Edit? I used to have a standard set of fonts in Text Edit but now they are all gone. Now all I have are "Hei," "Kai" and "BiauKai" in my font options. So I went to Font Book and enabled a few of my fa