Java Logger incrementing thread ids for a thread spawnned via JNI

Hi all,
I have a Java Logger object that I am passing to a JNI dll written in C++.
If I spawn a thread from the JNI dll and log from that thread, the thread id in the log file increments for each log entry.
To test this I wrote an infinite loop on the thread to make sure that the logging originated from a single thread. The thread id keeps incrementing in the log and the memory usage of the process increases too. However, the thread count in Task Manager does not increase.
I will let the process run overnight to determine if the thread id will overflow or if an out of memory exception occurs.
Has anyone else seen this behavior? Does anyone know what I might be doing wrong? I'm using jre 1.5.1.
Thanks,
William

(1)
has anybody ever tried to use a native library from
JNI, when the library (Windows DLL) is not thread safe?
Now we want many Java clients.
That would mean each client makes its calls
to the library in its own thread. Because the library
is not thread safe, this would cause problems.Right. And therefore you have to encapsulate the DLL behind a properly synchronized interface class.
Now the details of how you have to do that depends: (a) does the DLL contain state information other than TLS? (b) do you know which methods are not thread-safe?
Depending on (a), (b) two extremes are both possible:
One extreme would be to get an instance of the interface to the DLL from a factory method you'll have to write, where the factory method will block until it can give you "the DLL". Every client thread would obtain "the DLL", then use it, then release it. That would make the whole thing a "client-driven" "dedicated" server. If a client forgets to release the DLL, everybody else is going to be locked out. :-(
The other extreme would be just to mirror the DLL methods, and mark the relevant ones as synchronized. That should be doable if (a) is false, and (b) is true.
(2)
Now we discussed to load the library several times -
separately for each client (for each thread).
Is this possible at all? How can we do that?
And do you think we can solve the problem in this
way?The DLL is going to be mapped into the process address space on first usage. More Java threads just means adding more references to the same DLL instance.
That would not result in thread-safe behavior.

Similar Messages

  • Native library NOT thread safe - how to use it via JNI?

    Hello,
    has anybody ever tried to use a native library from JNI, when the library is not thread safe?
    The library (Windows DLL) was up to now used in an MFC App and thus was only used by one user - that meant one thread - at a time.
    Now we would like to use the library like a "server": many Java clients connect the same time to the library via JNI. That would mean each client makes its calls to the library in its own thread. Because the library is not thread safe, this would cause problems.
    Now we discussed to load the library several times - separately for each client (for each thread).
    Is this possible at all? How can we do that?
    And do you think we can solve the problem in this way?
    Are there other ways to use the library, though it is not thread safe?
    Any ideas welcome.
    Thanks for any contributions to the discussion, Ina

    (1)
    has anybody ever tried to use a native library from
    JNI, when the library (Windows DLL) is not thread safe?
    Now we want many Java clients.
    That would mean each client makes its calls
    to the library in its own thread. Because the library
    is not thread safe, this would cause problems.Right. And therefore you have to encapsulate the DLL behind a properly synchronized interface class.
    Now the details of how you have to do that depends: (a) does the DLL contain state information other than TLS? (b) do you know which methods are not thread-safe?
    Depending on (a), (b) two extremes are both possible:
    One extreme would be to get an instance of the interface to the DLL from a factory method you'll have to write, where the factory method will block until it can give you "the DLL". Every client thread would obtain "the DLL", then use it, then release it. That would make the whole thing a "client-driven" "dedicated" server. If a client forgets to release the DLL, everybody else is going to be locked out. :-(
    The other extreme would be just to mirror the DLL methods, and mark the relevant ones as synchronized. That should be doable if (a) is false, and (b) is true.
    (2)
    Now we discussed to load the library several times -
    separately for each client (for each thread).
    Is this possible at all? How can we do that?
    And do you think we can solve the problem in this
    way?The DLL is going to be mapped into the process address space on first usage. More Java threads just means adding more references to the same DLL instance.
    That would not result in thread-safe behavior.

  • Can't get Thread IDs to display in server.log or syslog

    I'm trying to capture the Java thread IDs for a custom application. According to the SunOne documentation, the thread IDs are only available if you configure the app to use the syslog for logging... even then, the thread IDs are optional.
    I've configured the app server to log through the syslogd and turned up the logging to finest. Still no thread IDs output to the log. Any suggestions?

    I've read that page - several times. I still can't it to work. Part of the problem that page is that it's talking about adding an existing WIT to the backlog, instead of a custom WIT.
    I inherited a customized template and I'm trying to further customize it, which is probably adding to my struggle. Can you spot anything wrong or missing here?
    From categories.xml:
    <CATEGORY name="Team Backlog Item Category" refname="MyCompany.TeamBacklogItemCategory">
    <DEFAULTWORKITEMTYPE name="User Story" />
    <WORKITEMTYPE name="Spike" />
    <WORKITEMTYPE name="Bug" />
    <WORKITEMTYPE name="Technical Story" />
    <WORKITEMTYPE name="Report" />
    </CATEGORY>
    From process Settings:
    <RequirementBacklog category="MyCompany.TeamBacklogItemCategory" pluralName="Team Backlog Items" singularName="Team Backlog Item">
    <States>
    <State value="New" type="Proposed" />
    <State value="Approved" type="Proposed" />
    <State value="Committed" type="InProgress" />
    <State value="Done" type="Complete" />
    </States>
    <Columns>
    <Column refname="System.WorkItemType" width="100" />
    <Column refname="System.Title" width="300" />
    <Column refname="System.State" width="100" />
    <Column refname="Microsoft.VSTS.Common.Priority" width="50" />
    <Column refname="Microsoft.VSTS.Scheduling.Effort" width="50" />
    <Column refname="System.IterationPath" width="200" />
    <Column refname="System.Tags" width="200" />
    </Columns>
    <AddPanel>
    <Fields>
    <Field refname="System.Title" />
    </Fields>
    </AddPanel>
    </RequirementBacklog>
    Also, do I have to do anything special to get the web portal to "refresh" after making changes like this?
    Thank you. 

  • Thread ID for servlets implementing SingleThreadModel

    Container creates different instances for every request to a Servlet implementing SingleThreadModel. So I tried to print thread IDs for such a Servlet by calling Thread.currentThread().getId(). I expected different thread IDs for every request to this Servlet. But what I noticed is - the same thread ID is logged several times (I got thread id 98 and 99 more than once). Can someone please explain why this is behaving like that?

    If container creates a thread pool and if it assigns different requests to same thread (fetched from the pool), then what's the point in creating multiple instances of one servlet?

  • Waiting for many threads

    Hey guys,
    I know how to make one thread wait for another named thread to complete, but how do u make a thread wait for many threads to complete with the added problem of not knowing the names of the threads your waiting for? Looked and been trying for ages but can't get anything to work.
    Thanx
    Lisa

    No i saw it, pehaps i should rephrase with a question, how would you go about giving all these threads a reference? If it ain't obvious already am not great with java and if someone could tell me how to give the threads spawned references it would be great.
    As ive explained the code is really long so am not going to waist peoples time by posting it. Here is basically how i am spawning the threads "willy-nilly" style.
         while ((p < searchTerms.size())&&(p < 30)){
             term = (searchTerms.elementAt(p)).toString();
             NetChecker nc = new NetChecker(term,excludedAdds,refWeb);
             searchClasses.addElement(nc);     
             new Thread(nc).start();
             p++;
         } the classes all return web addresses in a vector, thats why i need all the threads to complete so i can collect all the results
    Thanx
    Lisa

  • Transfer a Jpeg From Delphi to Java via JNI?

    Hi Guys,
    I am currently working on a project in which I have Windows DLL code that takes a screen capture (I'm using Delphi to write this). The result of this capture is stored as a TJpegImage. I have my Delphi code hooked to Java code (which the main program is written in) via JNI. I am trynig to transfer the Jpeg in a format in which Java can easily take it and make a BufferedImage out of it. How can I go about this? I have a few ideas, but I want to do it in the most efficient way possible. If someone knows how to do this, can they please share the solution with me?
    Thanks,
    -Tony

    whome0,
    Yes, thanks, that's exactly what I've been using. Basically, I'm at the point now where I know how to transfer the bytes, but for some reason, when I do this on the Java end:
    ByteArrayInputStream input = new ByteArrayInputStream( byteArr );
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( input );
    BufferedImage bi = decoder.decodeAsBufferedImage();
    I get this error:
    com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts with 0x60 0x23
    at sun.awt.image.codec.JPEGImageDecoderImpl.readJPEGStream(Native Method)
    at sun.awt.image.codec.JPEGImageDecoderImpl.decodeAsBufferedImage(Unknown Source)
    at com.sun.media.protocol.screen.LiveStream.read(LiveStream.java:166)
    at com.sun.media.parser.RawBufferParser$FrameTrack.transferData(RawBufferParser.java:725)
    at com.sun.media.protocol.screen.LiveStream.run(LiveStream.java:235)
    at java.lang.Thread.run(Unknown Source)
    I am baffled at this point, because I do a byte count before I send from my Delphi code, and a byte count on the Java receiving end, and they are identical. Looking at other JPGs I have on my hard drive, they begin in the same manner that this file does. So I'm not sure what's going on here.
    -Tony

  • How To:  Use Shutdown thread to flush Java Logger.

    I use the Java Logger as follows:
    Logger log = Logger.getLogger("company-name-here");but notice that when exiting the application the last few messages are not printed out
    to the log, even if I put a one second delay in the applications Shutdown Hook.
    I want to get every single log message before the JVM is allowed to shut down,
    would anyone know of a way to do this? Could you for example attach a
    LogHandler to flush the messages?
    Thank.

    But I've got two shutdown hooks associated with this application
    In both I log a message when the shutdown hook starts, AND another when it finishes.
    In the best case I might see both Shutdown hooks start messages, but I've not seen
    the "shutdown hook is finished" log in the dozen times I've looked for it.Note that the logging framework probably has its own shutdown hook, to flush buffered messages before stopping logging: javax.logging certainly has one, as witnessed in a recent thread .
    Shutdown hooks are threads objects, and as per the API javadoc +"the virtual machine (...) will start all registered shutdown hooks in some unspecified order and let them run concurrently"+, so you may very well have an unfortunate scheduling where the logging is stopped before the "last" log messages get through.
    The library may refuse the last log messages with an exception (see the thread linked above), but you have no guarantee of even being notified of that (check the err output of the first process).
    Thus my question. These log messages are going to a Swing window in another
    application, so it is possible that maybe something about the inter-process
    communication that gets shutdown prematurely.And to reduce the list of suspects, you should try if possible to eliminate this possibility, by experimenting with a plain-old file- or console-targetted logger, that does not run through this "remote logging" machinery.
    Good luck.
    J.

  • Custom thread pool for Java 8 parallel stream

    It seems that it is not possible to specify thread pool for Java 8 parallel stream. If that's so, the whole functionality is useless in most of the situations. The only situation I can safely use it is a small single threaded application written by one person.
    In all other cases, if I can not specify the thread pool, I have to share the default pool with other parts of the application. If someone submits a task that takes a lot of time, my tasks will get stuck. Is that correct or am I overlooking something?
    Imagine that someone submits slow networking operation to the fork-join pool. It's not a good idea, but it's so tempting that it will be happening. In such case, all CPU intensive tasks executed on parallel streams will wait for the networking task to finish. There is nothing you can do to defend your part of the application against such situations. Is that so?

    You are absolutely correct. That isn't the only problem with using the F/J framework as the parallel engine for bulk operations. Have a look http://coopsoft.com/ar/Calamity2Article.html

  • How to write JDBC code in a java thread? for network programming

    Hii guys, i am new to java network programming. I developed small swing application for stock controlling in a shop, so i need to run the database in a server. i try the peer to peer scenario, but the response is too late and the application get stuck. there i wl put my data base java class
    please help me for this, how can i change this java class to networked JDBC
    import com.mysql.jdbc.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class ConnectionSet {
    private String severIp = "localhost";
    private String severPort = "3306";
    private String userName = "root";
    private String password = "123";
    private ResultSet rs;
    public void setSeverIp(String Ip) {
    severIp = Ip;
    public void setSeverPort(String Port) {
    severPort = Port;
    public void SetUserName(String Name) {
    userName = Name;
    public void setPassword(String passWord) {
    password = passWord;
    public ResultSet getResult(String url) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cc = (Connection) DriverManager.getConnection("jdbc:mysql://" + getSeverIp() + ":" + getSeverPort() + "/suriyalanka", getUserName(), getPassword());
    Statement s = cc.createStatement();
    rs = s.executeQuery(url);
    // java.sql.ResultSet rs = (ResultSet) DriverManager.getConnection("jdbc:mysql://"+getSeverIp()+":"+getSeverPort()+"/suriyalanka",getUserName(), getPassword()).createStatement().executeQuery(url);
    return rs;
    public Connection getConnection() throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cc = (Connection) DriverManager.getConnection("jdbc:mysql://" + getSeverIp() + ":" + getSeverPort() + "/suriyalanka", getUserName(), getPassword());
    return cc;
    public void setResult(String url) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cc = (Connection) DriverManager.getConnection("jdbc:mysql://" + getSeverIp() + ":" + getSeverPort() + "/suriyalanka", getUserName(), getPassword());
    Statement s = (Statement) cc.createStatement();
    s.executeUpdate(url);
    public String getSeverIp() {
    return severIp;
    public String getSeverPort() {
    return severPort;
    public String getUserName() {
    return userName;
    public String getPassword() {
    return password;
    please help me for this, how can i change this java class to networked JDBC
    Edited by: 798670 on Sep 29, 2010 6:04 AM

    Have you verified that your mysql allows network connections?
    In order to allow network connections you have to comment or remove line "skip-networking" in my.ini(windows) or my.cnf(unix) configuration files of your mysql instance.
    Or if you have the mysql administrator installed
    MySQL Administrator / Startup Variables / Disable networking (uncheck)
    By!

  • Jdk1.4 stacktrace for arbitrary thread

    I realize in jdk1.5 you can get the stack trace for an arbitrary thread (not the current thread), but is there anyway to do it in jdk1.4? (programmatically -- not control break)

    ...and here is a quickie I wrote to try out java.lang.management.ThreadInfo.
    import java.lang.management.ManagementFactory;
    import java.lang.management.ThreadMXBean;
    import java.lang.management.ThreadInfo;
    import java.lang.reflect.Method;
    public class ThreadMX
        private static int STACK_TRACE_DEPTH = 20;
        public static void main(String args[])
         throws Exception
         // Demo deadlock detection
         Object george = new Object();
         Object lass = new Object();
         synchronized (lass) {
             new Deadlock(george, lass).start();
             new Deadlock(lass, george).start();
         Util.sleep(500); // Give 'em time to get locked
         System.out.println(stackInfo(System.getProperty("line.separator")));
        static class Util
         static void sleep(int time)
             try {
              Thread.sleep(time);
             } catch (Exception e) {}
        static class Deadlock
         extends Thread
         private Object a, b;
         Deadlock(Object a, Object b)
             this.a = a;
             this.b = b;
             setDaemon(true);
         public void run()
             synchronized (a) {
              Util.sleep(100);
              synchronized (b) {
                  System.out.println("never gets here");
        public static String stackInfo(String separator)
         StringBuffer buf = new StringBuffer();
         ThreadMXBean bean = ManagementFactory.getThreadMXBean();
         Class bean_class = ThreadMXBean.class;
         buf.append("live threads: ");
         buf.append(call(bean, bean_class, "getThreadCount"));
         buf.append(separator);
         buf.append("peak live threads: ");
         buf.append(call(bean, bean_class, "getPeakThreadCount"));
         buf.append(separator);
         buf.append("total started threads: ");
         buf.append(call(bean, bean_class, "getTotalStartedThreadCount"));
         buf.append(separator);
         buf.append("live daemon threads: ");
         buf.append(call(bean, bean_class, "getDaemonThreadCount"));
         buf.append(separator);
         buf.append("contention monitoring supported: ");
         buf.append(call(bean, bean_class, "isThreadContentionMonitoringSupported"));
         buf.append(separator);
         buf.append("contention monitoring enabled: ");
         buf.append(call(bean, bean_class, "isThreadContentionMonitoringEnabled"));
         buf.append(separator);
         buf.append("current thread cpu time: ");
         buf.append(call(bean, bean_class, "getCurrentThreadCpuTime"));
         buf.append(separator);
         buf.append("current thread user time: ");
         buf.append(call(bean, bean_class, "getCurrentThreadUserTime"));
         buf.append(separator);
         buf.append("thread cpu time supported: ");
         buf.append(call(bean, bean_class, "isThreadCpuTimeSupported"));
         buf.append(separator);
         buf.append("current thread cpu time supported: ");
         buf.append(call(bean, bean_class, "isCurrentThreadCpuTimeSupported"));
         buf.append(separator);
         buf.append("thread cpu time enabled: ");
         buf.append(call(bean, bean_class, "isThreadCpuTimeEnabled"));
         buf.append(separator);
         buf.append("deadlocked threads: ");
         try {
             long ids[] = bean.findMonitorDeadlockedThreads();
             if (ids == null || ids.length == 0) {
              buf.append("none");
             } else {
              for (int n = 0; n < ids.length; n++) {
                  if (n != 0)
                   buf.append(", ");
                  buf.append(ids[n]);
         } catch (Exception e) {
             buf.append("[call to findMonitorDeadlockedThreads failed: " + e + "]");
         buf.append(separator);
         buf.append("thread stack dumps: ");
         dumpThreads(buf, bean, separator);
         return buf.toString();
        private static void dumpThreads(StringBuffer buf, ThreadMXBean bean, String separator)
         try {
             long ids[] = bean.getAllThreadIds();
             if (ids == null) {
              buf.append("null thread id array?!");
              return;
             buf.append(ids.length + " threads:");
             buf.append(separator);
             ThreadInfo info[] = bean.getThreadInfo(ids, STACK_TRACE_DEPTH);
             if (info == null) {
              buf.append("null thread info array?!");
              return;
             Class info_class = ThreadInfo.class;
             for (int n = 0; n < info.length; n++) {
              if (n != 0)
                  buf.append(separator);
              ThreadInfo thread = info[n];
              if (thread == null) {
                  buf.append("null thread in info[" + n + "]?!");
                  continue;
              buf.append("thread ");
              buf.append(call(thread, info_class, "getThreadId"));
              buf.append(" \"");
              buf.append(call(thread, info_class, "getThreadName"));
              buf.append("\"");
              buf.append(": state ");
              buf.append(call(thread, info_class, "getThreadState"));
              buf.append(", blocked time ");
              buf.append(call(thread, info_class, "getBlockedTime"));
              buf.append(", blocked count ");
              buf.append(call(thread, info_class, "getBlockedCount"));
              buf.append(", waited time ");
              buf.append(call(thread, info_class, "getWaitedTime"));
              buf.append(", waited count ");
              buf.append(call(thread, info_class, "getWaitedCount"));
              buf.append(", lock name ");
              buf.append(call(thread, info_class, "getLockName"));
              buf.append(", lock owner ");
              buf.append(call(thread, info_class, "getLockOwnerId"));
              buf.append(", lock owner name ");
              buf.append(call(thread, info_class, "getLockOwnerName"));
              buf.append(", suspended ");
              buf.append(call(thread, info_class, "isSuspended"));
              buf.append(", in native ");
              buf.append(call(thread, info_class, "isInNative"));
              buf.append(separator);
              dumpStacks(buf, thread, separator);
         } catch (Exception e) {
             buf.append("[error getting thread data: " + e + "]");
        private static void dumpStacks(StringBuffer buf, ThreadInfo thread, String separator)
         try {
             StackTraceElement stack[] = thread.getStackTrace();
             if (stack == null || stack.length == 0) {
              buf.append("\tno stack trace available");
              return;
             for (int n = 0; n < stack.length; n++) {
              if (n != 0)
                  buf.append(separator);
              StackTraceElement frame = stack[n];
              if (frame == null) {
                  buf.append("\tnull stack frame");
                  continue;
              buf.append("\t");
              buf.append(frame.toString());
              buf.append("\t");
              buf.append(frame.getClassName());
              buf.append(".");
              buf.append(frame.getMethodName());
              String file = frame.getFileName();
              if (file != null) {
                  buf.append("(");
                  buf.append(file);
                  int line = frame.getLineNumber();
                  if (line >= 0) {
                   buf.append(":");
                   buf.append(line);
                  buf.append(")");
              if (frame.isNativeMethod())
                  buf.append("(native code)");
         } catch (Exception e) {
             buf.append("[error getting thread stack trace: " + e + "]");
        private static String call(Object thiz, Class clazz, String method_name)
         try {
             Method method = clazz.getMethod(method_name, (Class[]) null);
             Object result = method.invoke(thiz, (Object[]) null);
             if (result == null)
              return "[null]";
             String result_str = result.toString();
             if (result_str == null) // Paranoia
              return "[null toString()]";
             return result_str;
         } catch (Exception e) {
             return "[call to " + method_name + " failed: " + e + "]";
    }

  • Unique id for calling thread

    A stored proc can be called by any of the say 200 threads from within a pool of java connections that all sign on with say USER1. Another similar pool can call the same proc that are signed on with USER2. Inside the proc I need to store some SYS_CONTEXT info and retrive it within the same call. I cannot use a package HEADER variable beacuse this is not private to the thread. I cannot use a global variable in the package BODY because between storing the value in the BDY global variable and retrieving it another thread can call the same proc and access the BODY global variable.
    I decide to store in the info ina SYS_CONTEXT using a unique identifier for this thread as the ATTRIBUTE and the info in the VALUE. To compose the unique id for this thread I can issue the following SQl. Which combo will guarantee me a unique id for tis thread that called the stored proc. The calls are synchronous meaning once a thread obtains a connection from the pool to call the stored proc it does not give it up until the proc completes and returns a result to the thread.
    SELECT
    SYS_CONTEXT('USERENV','SESSIONID')
    ,SYS_CONTEXT('USERENV','SESSION_USER')
    ,SYS_CONTEXT('USERENV','SESSION_USERID')
    , ,SYS_CONTEXT('USERENV','SID')
    ,SYS_CONTEXT('USERENV','HOST')
    ,SYS_CONTEXT('USERENV','INSTANCE')
    INTO
    v_sessionid
    ,v_session_user
    ,v_session_userid
    ,v_host
    ,v_instance
    FROM
    DUAL
    ;

    Please don't abuse the forums by posting in many places.
    General Database Discussions

  • Java threading problem... threads only work on 1 processor

    I've got a iterative deepening problem that i have to parallelize. As far as i know i did everything correctly however everything seems to be running on 1 processor instead of 2 processors. As far as i know i am using threads (-Xprof either defines them as thread-1 thread-2 or pool1-thread1,depending on the method used for issueing)
    the worker thread is:
    public int solutionsT(Board board, int currentDepth) {
            int temp = 0;
            int result = 0;
            if (board.distance() == 0) {
               return 1;
            if (board.distance() > board.bound()) {
                return 0;
            Board[] children = board.makeMoves();
            result = 0;
            for (int i = 0; i < children.length; i++) {
                if (children[i] != null) {
                    temp = solutionsT(children, currentDepth + 1);
    if(temp != 0){
    result += temp;
    return result;
    public void run() {
    int temp =0;
    int i = 0;
    while(true){
    while(bag.size() !=0){
    bag.putSolution(solutionsT(bag.get(),1));
    try{   
    barrier.await();
    }catch(Exception e){}
    it get's it's input from a bag that is filled before the iteration begins. (once the bag is filled it trips a barrier) this worker thread is a implementation of Runnable
    This piece of code is used to make the thread object and to issue it
    public SolutionThread(int numberOfThreads) {
       thread = numberOfThreads;
       bag = new bagOfBoards();
       barrier = new CyclicBarrier(thread+1);
       if(thread > 1){
          ExecutorService threadExecutor = Executors.newFixedThreadPool( thread );
          solution = new ThreadTest[thread];
          bag = new bagOfBoards();
          for(int i = 0;i<thread;i++){
             solution[i] = new ThreadTest(bag, lock, barrier, i);
             threadExecutor.execute(solution);
    finally this is the code which is used to acces the bag and get a board.
    synchronized public Board get() {
                if (size > 0) {
                size--;
                Board result = bag[size];
                return result;
            } else {
             return null;
        }since this method is synchronized and it always returns something (either null or a board) and the worker tests for this. there is no race condition here.
    furter more. the main thread is a loop. It fills te bags with an intial state. then it trips the barrier and waits for the workers to do the work. the workers then process the bag until it hits zero and then trip the barrier so that the main thread can do the next iteration (and fill the bag)
    p.s. i know the code is a bit messy, but i want to get the threading to work. As of now i relaly don't understand why the threads are just running on 1 processor instead of 2 processors. not only that. the excecution time is nearly the same as that of a sequential equivalent.
    p.s.2 the code is parallisable. and it is run on a smp system.
    Message was edited by:
    jstrike

    i'm very sure that the jvm and os support smp. the
    problem really should be in the code.I don't see how this can be the case. There's nothing in the Java language that deals with how threads are assigned to processors (at least not as far as I know) so there isn't anything you can do in your code to affect that.
    Or did you meant that i have to tell the jvm in the class that
    there is support for multiple processorsThat would be the only possibility. I have no idea whether it can be done or not, though.

  • No externally managed transaction is currently active for this thread

    Got the following exception after updating an entity bean and call persist method. Code the given below the exception.
    Exception [TOPLINK-23010] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.TransactionException
    Exception Description: No externally managed transaction is currently active for this thread
    public Object persistEntity(Object entity) {
    em.flush();
    em.persist(entity);
    return entity;
    private void modifyUser (Iuser user, String newHandle, Hashtable userDetails) throws UnknownException, WarningException {
    if (user == null) {
    throw new WarningException (new CatalogHelper("ITOOLS_000015", "to modify a user"));
    boolean handleUpdate = false;
    if ((newHandle != null) && !newHandle.equals("^\\s*$")) {
    handleUpdate = true;
    String oldHandle = user.getUserhandle();
    if (handleUpdate && oldHandle.equalsIgnoreCase(newHandle)) {
    handleUpdate = false;
    if (!handleUpdate && (userDetails == null) || (userDetails.size() == 0)) {
    return;
    if (handleUpdate) {
    userDetails.put("userhandle", newHandle);
    IToolsUtil.validateInputData("iuser", userDetails, false);
    if (handleUpdate) {
    userDetails.remove("userhandle");
    System.out.println("handleUpdate " + handleUpdate);
    // For User admin, handle, isactive, isadmin cannot be changed.
    if (oldHandle.equals("admin")) {
    if (handleUpdate) {
    throw new WarningException (new CatalogHelper("ITOOLS_000045", "Handle"));
    String active = (String)userDetails.get("isactive");
    if ((active != null) && !active.equals("Yes")) {
    throw new WarningException (new CatalogHelper("ITOOLS_000045", "Is Active"));
    String admin = (String)userDetails.get("isadmin");
    if ((admin != null) && !admin.equals("Yes")) {
    throw new WarningException (new CatalogHelper("ITOOLS_000045", "Is Admin"));
    System.out.println("user transaction started");
    if (handleUpdate) {
    FinderMethods fm = new FinderMethods();
    try {
    fm.findByUserHandle(em, newHandle);
    throw new WarningException (new CatalogHelper("ITOOLS_000043", newHandle));
    } catch (ObjectNotFoundException onfe) {
    user.setUserhandle(newHandle);
    System.out.println("User handle modified");
    } catch (SQLException se) {
    se.printStackTrace();
    throw new UnknownException (new CatalogHelper("ITOOLS_100000", new Object[]{"modifyUser", se.getMessage()}));
    String lname = (String)userDetails.get("userlname");
    if (lname != null) {
    user.setUserlname(lname);
    String fname = (String)userDetails.get("userfname");
    if (fname != null) {
    user.setUserfname(fname);
    String email = (String)userDetails.get("useremail");
    if (email != null) {
    user.setUseremail(email);
    String passwd = (String)userDetails.get("userpasswd");
    if (passwd != null) {
    user.setUserpasswd(passwd);
    String active = (String)userDetails.get("isactive");
    if (active != null) {
    user.setIsactive(active);
    String admin = (String)userDetails.get("isadmin");
    if (admin != null) {
    user.setIsactive(admin);
    System.out.println("details are updated");
    persistEntity(user);
    System.out.println("committed");
    How to resolve this issue? I am using Jdeveloper 10.1.3.0.4 (SU4)
    regds
    -raju

    The stack trace is given below. This exception is occured at "em.flush()" method. I even tried removing em.flush() method. Even then I got the same exception.
    I tried a different way of overcome this problem. Used UserTransaction instance say "ut" before create / modify the entity bean and later comitted. In that case I am not getting any exceptions. However, commit is happening only when new instance is created, commit works, but modification of an existing instance, commit is not working. Looks like there is some serious problem with EJB 3.0 in OC4J. Basic functionality is not working.
    Stack trace when flush method is called:
    Local Exception Stack:
    Exception [TOPLINK-23010] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.TransactionException
    Exception Description: No externally managed transaction is currently active for this thread
         at oracle.toplink.exceptions.TransactionException.externalTransactionNotActive(TransactionException.java:98)
         at oracle.toplink.internal.ejb.cmp3.transaction.base.JTATransactionWrapper.checkForTransaction(JTATransactionWrapper.java:39)
         at oracle.toplink.internal.ejb.cmp3.base.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:322)
         at oracle.toplink.internal.ejb.cmp3.base.EntityManagerImpl.getActiveUnitOfWork(EntityManagerImpl.java:314)
         at oracle.toplink.internal.ejb.cmp3.base.EntityManagerImpl.flush(EntityManagerImpl.java:164)
         at com.itools.vs.model.session.AdminSessionBean.persistEntity(AdminSessionBean.java:57)
         at com.itools.vs.model.session.AdminSessionBean.createUser(AdminSessionBean.java:124)
         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:585)
         at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:53)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    Stack trace when persist method is called:
    Local Exception Stack:
    Exception [TOPLINK-23010] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.TransactionException
    Exception Description: No externally managed transaction is currently active for this thread
         at oracle.toplink.exceptions.TransactionException.externalTransactionNotActive(TransactionException.java:98)
         at oracle.toplink.internal.ejb.cmp3.transaction.base.JTATransactionWrapper.checkForTransaction(JTATransactionWrapper.java:39)
         at oracle.toplink.internal.ejb.cmp3.base.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:322)
         at oracle.toplink.internal.ejb.cmp3.base.EntityManagerImpl.getActiveUnitOfWork(EntityManagerImpl.java:314)
         at oracle.toplink.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:74)
         at com.itools.vs.model.session.AdminSessionBean.persistEntity(AdminSessionBean.java:57)
         at com.itools.vs.model.session.AdminSessionBean.createUser(AdminSessionBean.java:123)
         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:585)
         at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:53)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)

  • RemoteException: 111 java.rmi.ServerError: Error occurred in server thread

    Hi,
    I'm just new to the RMI field of JAVA. I'm trying to write a program that import the math.jar file in the server side. And the client end can invoke the methods of math.jar and get the value.
    I got the error messages as below:
    RemoteException: 111 java.rmi.ServerError: Error occurred in server thread; nested exception is:
         java.lang.NoClassDefFoundError: org/mathwhizz/Heron
    It can work well if I use source classes(*.class) directly instead of importing math.jar. The failure only happened when I try to make use of jar file. Thus I guess my setup and configuration should be ok. Is there anything I should be very careful if I try to run RMI and import a jar file in the program of server side ?
    Do I need to use JNLP and web start application in this issue?
    I'm appreciated for your responses...thanks...
    Sincerely,
    Brandon

    I've got a problem with rmi, when I launch my server, I have this error:
    Erreur du remote: java.rmi.ServerError: Error occurred in server thread; nested exception is:
    java.lang.NoClassDefFoundError: com/borland/dx/dataset/DataSetData
    Help me please
    Thank you

  • Stack size for native thread attaching to JVM

    All:
    I have a native thread (see below, FailoverCallbackThread) that attaches to the JVM and does a Java call through JNI. The stack size for the native thread is 256KB.
    at psiUserStackBangNow+112()@0x20000000007a96d0
    at psiGuessUserStackBounds+320()@0x20000000007a8940
    at psiGuessStackBounds+48()@0x20000000007a8f60
    at psiGetPlatformStackInfo+336()@0x20000000007a9110
    at psiGetStackInfo+160()@0x20000000007a8b40
    at psSetupStackInfo+48()@0x20000000007a5e00
    at vmtiAttachToVMThread+208()@0x20000000007c88b0
    at tsAttachCurrentThread+896()@0x20000000007ca500
    at attachThread+304()@0x2000000000751940
    at genericACFConnectionCallback+400(JdbcOdbc.c:4624)@0x104b1bc10
    at FailoverCallbackThread+512(vocctx.cpp:688)@0x104b8ddc0
    at start_thread+352()@0x20000000001457f0
    at __clone2+208()@0x200000000030b9f0
    This causes stack overflow in Oracle JRockit JVM. (It does not cause overflow with Oracle Sun JDK.) Is there a recommended stack size for this use case for JRockit? Is there a way to compute it roughly?
    Platform Itanium 64 (linux)]
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    BEA JRockit(R) (build R26.4.0-63-63688-1.5.0_06-20060626-2259-linux-ia64, )
    mp

    How do I found default heap size, stack size for the
    thread, number of threads per jvm/process supported ?The threads is OS, OS install and jvm version specific. That information is also not useful. If you create the maximum number of threads that your application can create you will run out of memory. Threads require memory. And it is unlikely to run very well either.
    The default heap size and stack size are documented in the javadocs that explain the tools that come with the sun jdk.
    and how the above things will vary for each OS and how
    do I found ? Threads vary by OS, and OS install. The others do not (at least not with the sun jvm.)
    If I get "OutOfMemoryError: Unable to create new native thread" Most of the time it indicates a design problem in your code. At the very lease, you should consider using a thread pool instead.
    I found in one forum, in linux you can create maximum
    of 894 threads. Is it true ?Seems high since in linux each thread is a new process, but it could be.

Maybe you are looking for

  • External SATA RAID no longer works after 10.5.5 update

    After updating to 10.5.5, my external RAID (Sbox) (RAID 10) is no longer recognized – The SATA card is functioning correctly – I can attach a single external SATA drive without problem – all ROM has been updated (working with Sonnet) and we confirmed

  • My mac was stolen how can I block it?

    please answer as soon  as possible

  • Converting I-tunes 6.0 M4p files to mp3

    I have a number of files that have been downloaded from I-tunes 6 that will not play in my Dj CD players. My CD players play Mp3 files but not the newer AAC files from I-tunes 6. Is there a program or a way to convert the file, by keeping the file on

  • 5.2  --  GOTO SE16 and enter TSTC for TABLE NAME.  TCODE FIELD /VIRSA*

    Should the following tcodes work?  If so, how do I troubleshoot the ones that don't work?  If not, how do they get configured to work?  Can someone provide a link for documentation? TCODE                                  TTEXT                        

  • Problem with grep and awk...

    mplayer -nosound -vo null -frames 1 movie.avi My last serveral line of output is: VDec: vo config request - 720 x 540 (preferred colorspace: Planar YV12) VDec: using Planar YV12 as output csp (no 0) Movie-Aspect is 1.33:1 - prescaling to correct movi