Help on multithreaded app

  • Nobody/Anonymous

    I have been playing somewhat with Microlog, but I have been experiencing some problems in a multithreaded application... I have several classes but they all use one single Logger object (within the main MIDlet), to begin with is this common practice or should every class have its own Logger method ? And if so how do I place all data into a single RMS ?
    Mostly the problem is that my application will delete the log at some point (after a check with a server) whilst the other threads/classes might still try to log something so at some point I get :

    Exception: javax/microedition/rms/InvalidRecordIDException
    Failed to log to RecordStore javax.microedition.rms.InvalidRecordIDException

    errors, this following the deletion of the log through the loader.clearLog() method...
    any ideas and/or considerations ?

    • Johan Karlsson

      Johan Karlsson - 2009-05-27


      I have tried to make the RecordStore thread-safe, but this scenario is not something that I have considered. But I think that it would be possible to solve your issue by making Microlog a little bit "smarter". However I will have to take a deeper look into the code to come up with a solution. Thus I will have to get back with you on that.

      I think that it is appropriate to use one RMS/MIDlet. Even if you use one or several Logger instances, there are only a limited number of RMSs available. It is therefore vital that the RecordStoreAppender is thread-safe.

      The reason for using several (named) Loggers could be that you wish to separate the logging statements. For example, you could use the Log4j standard that each class have a logger with the class-name as its name. To do this you use:

      Logger.getLogger(YourClass.class) to create your logger object.

      Best Regards

    • Nobody/Anonymous

      That last one your mentioning (logger with class name) will that result in several RMS's (one for each class name) or in one single RMS ?
      But I did  solve the problem by using the Logger.clear() method instead of the Appender one.
      Or at least I aint getting the same errors anymore ;)

      • Johan Karlsson

        Johan Karlsson - 2009-05-28


        even if you use several logger instances, they should log to the same record store. But this is not tested very much...

        Nice that you got it to work with Logger.clear() method.

        Best Regards


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks