C++ stringstream in multithreaded environment

We are using a lot of stringstream objects in multiple locations in our code. The objects are not shared across threads but still program crashes in multithreaded environment. The investigation shows that the program crashes when we use both insertion & extraction operators (stringstream ::operator << and stringstream ::operator >> ). The program crashes at random locations, always pointing to stringstream in our code. We receive SIGBUS, or SIGSEGV or (sometimes) SIGABRT signals.
We need to know how to use stringstream in Multithreaded environment.
Any help will be highly appreciated.
Versions:
Compiler Version: CC: Sun C++ 5.9 SunOS_sparc Patch 124863-05 2008/06/03
Machine: SunOS bear 5.10 Generic_127111-11 sun4u sparc SUNW,Sun-Fire-V490
/usr/lib/sparcv9/libCstd.so.1: Sun SUNWlibC SunOS 5.10 Patch 119963-08 2006/09/20
Following is the test program (creates 20 threads & does insertion-extraction) & Makefile below it.:
{color:#0000ff}#include <string>
#include <sstream>
#include <pthread.h>
#include <thread.h>
#include <vector>
using namespace std;
extern "C" void* ThreadFunc( void* p )
for(int i=0 ; i < 1000000 ; i++){
string str("dummy");
stringstream buf;
buf << "Dummy Data " << i ;
buf >> str;
return NULL;
int main (int argc, char** argv)
try {
pthread_t thread;
vector<pthread_t> threads;
for(int i=0; i < 20 ; i++) {
pthread_create(&thread, NULL,ThreadFunc, NULL);
threads.push_back(thread);
int rc;
void* status;
for(int t=0; t < 10; t++) {
rc = pthread_join(threads[t], &status);
if (rc) {
// cout << "ERROR in joining thread " << threads[t] << endl;
return (-1);
//cout << "Completed joining thread " << threads[t] << " with status " << (long)status << endl;
} catch (...) {
//cout << "some exception\n";
return 0;
{color}
////////Makefile/////////////
{color:#ff00ff}CC=/appl/toolbox/studio12-July08/SUNWspro/bin/CC
CPP =${CC} -m64 -mt -xarch=sparcvis2 -g
OFILES = ${SOURCE:.cpp=.o}
PROG = stringstreamtest
SOURCE = main.cpp
{color}
{color:#ff00ff}${PROG}:${OFILES}
${CPP} ${OFILES} -o $@
%.o:%.cpp
${CPP} -c $< -o $@
{color}
{color:#ff00ff}clean:
${RM} *~
${RM} *.o
${RM} -r ${PROG}
${RM} -f .make.state
.KEEP_STATE:{color}

The stringstream class is thread-safe, but you must provide your own guards around string and stream objects that are shared among threads. That is, the library provides internal guards that you could not provide yourself, but if two threads modify the same string object (or any non-atomic object, for that matter) at the same time, the results are unpredictable.
You have a rather old version of libCstd on your system. Please update to the current SUNWlibC patch
sparc: 119963-12
x86 : 119964-12
You can get the patch from [http://sunsolve.sun.com]
Some other things to check:
Be sure that libCrun and libCstd are linked only as shared (.so) libraries, and not as archive (.a) libraries.
Do not use the linker -Bsymbolic option when creating shared libraries - it can cause program crashes particularly when using the string class.
Do not use -xarch=v8 or -xtarget=v8 options, since it can cause loss of thread synchronization when running on current architectures. (The v8 architecture dates from before the UltraSPARC was introduced in the mid 1990's.)
Finally, you should check your code for the usual programming errors that can lead to crashes:
- using an invalid pointer
  - uninitialized
  - dangling (points to object that no longer exists)
  - incremented or decremented outside object bounds
  - points other than to an object start address
- deleting an object more than once
- reading or writing outside object bounds
- failing to guard shared object in multi-threaded code
- race condition in multi-threaded codeThe program failure usually occurs far away in space and time from the
actual error.
These errors do not always lead to a program crash. An invalid pointer
might sometimes by accident point to a harmless location. A race
condition can go millions of cycles without causing a problem. Access to
a deleted object can succeed by accident if the memory was not re-used.
Any change in program code or compiler options can turn one of these
programming errors into an actual failure, or the other way around.
Try running the program under dbx with Run-Time Checking enabled. RTC
will find many of these errors. In Sun Studio 12, the Thread Analyzer
tool will find race conditions.

Similar Messages

  • Best way to generate an incrementing ID in multithreaded environment

    Hi
    I have a "best practice" kind of question.
    I need to insert a record in an Oracle table where primary key is an incrementing numeric ID. In order to insert a new record, first i need to figure out what the maximum ID is and then increment it.
    In a multithreaded environment, this can cause an error when, let's say, there are 2 threads, and each one is simultaneously querying the table for the max ID. Each query will return the same result and hence only 1 query will succeed at inserting the new record. The second insert will cause a primary key conflict when trying to execute.
    Is making the code synchronized the best solution in this situation or is there a better way?
    Thanks in advance.

    Hi,
    using Oracle sequence could be easy and effective, just insert sequence.NEXTVAL into the particular column. Oracle should take care of possible conflicts, it should always provide different (means incremented) value.
    I dont recommend using agregate function MAX(column).
    Good luck,
    Rgds
    Miroslav

  • Question about security context in multithreading environment

    I have a need to make concurrent calls to multiple EJBs in parallel threads. Let's
    say I establish the security context once by creating an InitialContext with given
    security principal and credential. With the security context active, I spawn multiple
    threads from the current thread and in each of those threads I make a call to
    a secure EJB method, which my security principal is allowed to access. My question
    is, will the same security context be established in each of the spawned thread
    so that my EJB calls succeed? For various reasons it's not feasible to login in
    each of the spawned threads, only to login once from the main thread.
    I tried this with WebLogic 6.1sp3 and it seems to work as expected. However, I
    have not been able to find any documentation on how security contexts are propagated
    to spawned threads. All I could find was a statement that when an InitialContext
    is created, the corresponding security context becomes associated with the current
    thread.
    My concern is that even though it works in WebLogic 6.1, it may no longer work
    the same way in WebLogic 7.0 or later. And will it work when the JNDI login mechanism
    is replaced by JAAS? If any WebLogic/security guru out there could give me some
    info on how WebLogic security contexts work in a multithreaded environment, I
    would be much obliged.
    Thanks in advance!
    Minh-Tue Vo

    "Minh-Tue Vo" <[email protected]> wrote in message
    news:[email protected]..
    >
    \> My concern is that even though it works in WebLogic 6.1, it may no longer
    work
    the same way in WebLogic 7.0 or later. And will it work when the JNDIlogin mechanism
    is replaced by JAAS? If any WebLogic/security guru out there could give mesome
    info on how WebLogic security contexts work in a multithreadedenvironment, I
    would be much obliged.
    With the JAAS model, you should be able to get a subject once and then do a
    runas in the spawned threads.

  • Using directory session in a multithreaded environment

    Hi,
    We are trying to use a directorySession object of PAPI for creating participants dynamically but it fails if we use it in a multithreading environment. Is there any limitation on using the directory session in a multithreading enviroment?

    Did you figure out how to do this? We ended up having to track the number of sessions using the service and close it only when there were none. However, this did not solve the problem completely. There seems to be a conflict when running our servlet app (which uses PAPI) on different machines talking to the same BPM. A thread on one machine opens, uses, closes a session and service while a thread on another machine opens a session and in the middle of using it, it dies.

  • Activating javacorba client on Multithreaded environment

    Hi,
    I have a java corba client communicating C++ corba server. This java corba client gets activated in multithreaded environment (i.e. multiple threads try to communicate with C++ corba server using this java corba client simultaniously).
    This java client starts the transaction using TransactionCurrent object before sending data corba server.
    I am getting an error for the mentioned code below code:
    tran_curr_oref =
    bootstrap.resolve_initial_references("TransactionCurrent");
    org.omg.CORBA.NO_PERMISSION: vmcid: 0x54555000 minor code: 1019 completed: Maybe
    at com.beasys.Tobj_BootstrapRemote.resolve_initial_references(Tobj_BootstrapRemote.java:615)
    at com.beasys.Tobj_Bootstrap.resolve_initial_references(Tobj_Bootstrap.java:243)
    at com.dhl.emea.javacorbaclient.PEVWrapperClient.TuxSend(PEVWrapperClient.java:188)
    at com.dhl.emea.javacorbaclient.CreateThread.run(CreateThread.java:78)
    at java.lang.Thread.run(Unknown Source)
    Now My question is
    1) Can i have multithreaded java clients with each thread activating seperate transactions?
    2) Is there any work around so that i instantiate TransactionCurrent object once and the remaining threads use the same object to start and stop the transaction?
    Any help on this appreciated.
    Thanks and Regards
    Prashanth

    Hi Prashanth,
    Assuming you are using a remote CORBA/Java client to communicate with Tuxedo, then you are most likely using IIOP to communicate with the Tuxedo ISL/ISH. In this environment, you only have a single connection to Tuxedo and the ISL only allocates a single client context for your connection. As a result, even though your client may be multi-threaded, all threads are going to share the same connection and the same context including transaction and security context. The reason for this is that Tuxedo uses a delegation model and delegates security and transaction contexts to the ISL.
    If you use another Java ORB other than the Tuxedo Java ORB, you might be able to get it to open a separate connection to Tuxedo for each thread and thus each thread could have it's own Tuxedo security and transaction context in the server. But this would be at the cost of a connection per client thread which may create way to many connections to Tuxedo.
    If your code is running inside WLS and you are using WTC, then you can have a unique transactions and security context per thread.
    Regards,
    Todd Litle
    BEA Tuxedo Engineering

  • Tpinit and tpterm in multithreaded environment

    Hello,
    I have a question about the way a Tuxedo WS client allocates and releases connections
    to Tuxedo server in a muti threaded environment. I call once tpinit() with the
    TPMULTICONTEXTS flags set ( I guess somme system resources are allocated) . I
    get the current context 'cc' calling tpgetcontext(), I communicate it to another
    thread so that it could talk with tuxedo server through this context. Next I call
    tpterm(), the current thread is set into the state TPNULLCONTEXT. But i noticed
    that any other new threads are able to REuse the former 'cc'.... does tpterm()
    release the system resources that are associated with the connection 'cc' ? it
    looks like it doesn't . How can i totally invalidate the former current context
    'cc' ?
    Thanks..
    Cryo

    Are you saying that after doing tpterm, your connection stays open, and
    threads can still do tpcalls on that context?
    Tpterm should be dropping the connection.
    Make sure that you are running the latest patch level.
         Scott Orshan
    Cryo wrote:
    >
    Hello,
    I have a question about the way a Tuxedo WS client allocates and releases connections
    to Tuxedo server in a muti threaded environment. I call once tpinit() with the
    TPMULTICONTEXTS flags set ( I guess somme system resources are allocated) . I
    get the current context 'cc' calling tpgetcontext(), I communicate it to another
    thread so that it could talk with tuxedo server through this context. Next I call
    tpterm(), the current thread is set into the state TPNULLCONTEXT. But i noticed
    that any other new threads are able to REuse the former 'cc'.... does tpterm()
    release the system resources that are associated with the connection 'cc' ? it
    looks like it doesn't . How can i totally invalidate the former current context
    'cc' ?
    Thanks..
    Cryo

  • Help on calling static method in a multithreaded environment

    Hi,
    I have a basic question.. pls help and it is urgent.. plss
    I have a class with a static method which does nothing other than just writing the message passed to a file. Now i have to call this static method from many threads..
    What actually happens ???
    Does all the thread start to execute the static method or one method executes while the other threads wait for the current thread to complete execution?. I am not talking about synchronizing the threads...my question is what happens when multiple threads call a static method??
    Pls reply.. I need to design my project accordingly..
    Thanks
    Rajeev

    HI Omar,
    My doubt is just this..
    I wanted to know what might happen if two threads try to access a static method.. Logically only one thread can use the method since it is only only copy... but i was wondering what might happens if f threads try to access the same static method.. My Situation is this.. I have a cache which is just a hash table which will be only one copy for the whole application.. No when i get a request I have to check if the id is avaible in the cache. if it is available i call method 1 if not i call method2. Now Ideally the cache should be a static object and the method to check the id in the cache will be a normal instance method..
    I was just wondering what might happen if i make the method static.. If i can make it static i can can save a lot of space by not creating the object each time.. u know what i mean.. That y i wanted to know what happens..
    Rajeev

  • Using time() function in multithreaded application

    I am using time() function in a multithreaded application with NULL argument for getting current time.
    Some time it's observed that we get a time one minute earlier than current time (3600 seconds).
    Is there a problem in the usage of the function?
    I am using expression : currenttime = time(NULL);
    I had seen some people using following way - time(&currenttime );
    Will above two behaves differently in multithreaded environment?
    [I  am using  Sun C++ 5.5 compiler on Solaris 8]

    How do you compare actual time against the time seen by your threads? If your threads are printing the value from time(2) to stdout, it's possible that you're seeing an artifact of thread scheduling and/or output buffering.
    I really doubt that you have a concurrency problem, but anyway make sure that you include the -mt option on your compile line:
    CC -mt blahblahblah...

  • WLS10, Oracle 10g, EJB3, @GeneratedValue, PK collision multithreaded

    Hi forum readers,
    I have a little problem with the primary key generation in a multithreaded environment.
    I have the following:
    - Oracle 10g Express Database using the BEA thin non-xa driver without distributed transactions
    - EntityBean:
    @Entity
    @Table (name = "t_log")
    public class LogEntity implements Serializable {
         @Id
         @GeneratedValue(strategy=GenerationType.AUTO)
         private long id;
         @Lob
         private String message;
         public LogEntity(String message) {
              this.message = message;
         public LogEntity() {
         public String getMessage() {
              return message;
    Stateless Session Bean that just creates LogEntities:
    @Stateless
    @TransactionAttribute (TransactionAttributeType.REQUIRED)
    public class LogAccessBean implements LogAccessLocal{
         @PersistenceContext
         EntityManager em;
         public void log(int type, String message) {
              LogEntity log = new LogEntity(message);
              em.persist(log);
    The LogAccessLocalInterface:
    @Local
    public interface LogAccessLocal {
         public void log(String message);
    Webservice calling the StatelessSessionBean:
    @WebService (endpointInterface = "webservice.TestService")
    @Stateless
    public class TestEndpoint implements TestService {
         @EJB
         private LogAccessLocal log;
         public void log(String client) {
              log.log("This is a testmessage logged on: " + System.currentTimeMillis() + ", client: " + client);
    persistence.xml:
    --- snip ---
    <property name="kodo.jdbc.DBDictionary" value="oracle" />
    <property name="kodo.Multithreaded" value="true" />
    --- snip ---Everything works ok when the webservice is called in a single threaded environment, but as soon as I start using the WS by many different threads the server starts to throw exceptions as hell:
    (I use a perl script to call the webservice, and a shell script that forks multiple calls to the perl script.)
    ####<Sep 27, 2007 4:32:49 PM GMT+01:00> <Error> <EJB> <serverhost> <AdminServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1190907169990> <BEA-010026> <Exception occurred during commit of transaction Name=[EJB webservice.TestEndpoint.log(java.lang.String)],Xid=BEA1-5367F15A15000E47A569(19526372),Status=Rolled back. [Reason=Unknown],numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds since begin=0,seconds left=30,SCInfo[axs_jrockit+AdminServer]=(state=rolledback),properties=({weblogic.transaction.name=[EJB webservice.TestEndpoint.log(java.lang.String)]}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(CoordinatorURL=AdminServer+192.168.1.1:7001+axs_jrockit+t3+admin+7001+, XAResources={},NonXAResources={})],CoordinatorURL=AdminServer+192.168.1.1:7001+axs_jrockit+t3+admin+7001+): weblogic.transaction.RollbackException: Unknown reason
         at weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1818)
         at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:333)
         at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:227)
         at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:588)
         at weblogic.ejb.container.internal.BaseLocalObject.postInvokeTxRetry(BaseLocalObject.java:421)
         at weblogic.ejb.container.internal.BaseWSLocalObject.postInvokeTxRetry(BaseWSLocalObject.java:196)
         at webservice.TestEndpoint_qthlxq_WSOImpl.__WL_log_WS(TestEndpoint_qthlxq_WSOImpl.java:86)
         at jrockit.reflect.CompiledMethodInvoker.invoke0(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
         at jrockit.reflect.CompiledMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
         at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
         at weblogic.wsee.server.ejb.WsEjb.invoke(WsEjb.java:50)
         at weblogic.wsee.jaxws.WLSEjbInvoker.invoke(WLSEjbInvoker.java:135)
         at weblogic.wsee.jaxws.WLSInvoker.invoke(WLSInvoker.java:42)
         at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:247)
         at com.sun.xml.ws.server.sei.SEIInvokerPipe.process(SEIInvokerPipe.java:97)
         at weblogic.wsee.jaxws.MonitoringPipe.process(MonitoringPipe.java:98)
         at com.sun.xml.ws.protocol.soap.ServerMUPipe.process(ServerMUPipe.java:62)
         at com.sun.xml.ws.server.WSEndpointImpl$1.process(WSEndpointImpl.java:139)
         at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:153)
         at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:235)
         at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:97)
         at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:36)
         at weblogic.wsee.jaxws.JAXWSServlet.doPost(JAXWSServlet.java:218)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3370)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction;)Ljava.lang.Object;(Unknown Source)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2117)
    .>
    ####<Sep 27, 2007 4:32:49 PM GMT+01:00> <Warning> <JTA> <serverhost> <AdminServer> <[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1190907169990> <BEA-110401> <Ignoring error in afterCompletion. Object=weblogic.deployment.BasePersistenceContextProxyImpl$PersistenceContextCloser@129f553, Exception=<4|true|0.9.7> org.apache.openjpa.persistence.InvalidStateException: The context has been closed. The stack trace at which the context was closed is available if Runtime=TRACE logging is enabled.
    <4|true|0.9.7> org.apache.openjpa.persistence.InvalidStateException: The context has been closed. The stack trace at which the context was closed is available if Runtime=TRACE logging is enabled.
         at org.apache.openjpa.kernel.BrokerImpl.assertOpen(BrokerImpl.java:4290)
         at org.apache.openjpa.kernel.BrokerImpl.beginOperation(BrokerImpl.java:1726)
         at org.apache.openjpa.kernel.BrokerImpl.close(BrokerImpl.java:4012)
         at org.apache.openjpa.kernel.DelegatingBroker.close(DelegatingBroker.java:1284)
         at org.apache.openjpa.persistence.EntityManagerImpl.close(EntityManagerImpl.java:999)
         at weblogic.deployment.TransactionalEntityManagerProxyImpl.close(TransactionalEntityManagerProxyImpl.java:94)
         at weblogic.deployment.BasePersistenceContextProxyImpl$PersistenceContextCloser.afterCompletion(BasePersistenceContextProxyImpl.java:184)
         at weblogic.transaction.internal.ServerSCInfo$CallAfterCompletionsAction.run(ServerSCInfo.java:1595)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
         at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedExceptionAction;)Ljava.lang.Object;(Unknown Source)
         at weblogic.transaction.internal.ServerSCInfo.doAfterCompletion(ServerSCInfo.java:1028)
         at weblogic.transaction.internal.ServerSCInfo.callAfterCompletions(ServerSCInfo.java:996)
         at weblogic.transaction.internal.ServerTransactionImpl.callAfterCompletions(ServerTransactionImpl.java:2946)
         at weblogic.transaction.internal.ServerTransactionImpl.afterRolledBackStateHousekeeping(ServerTransactionImpl.java:2827)
         at weblogic.transaction.internal.ServerTransactionImpl.setRolledBack(ServerTransactionImpl.java:2803)
         at weblogic.transaction.internal.ServerTransactionImpl.globalRetryRollback(ServerTransactionImpl.java:3043)
         at weblogic.transaction.internal.ServerTransactionImpl.globalRollback(ServerTransactionImpl.java:2793)
         at weblogic.transaction.internal.ServerTransactionImpl.internalRollback(ServerTransactionImpl.java:397)
         at weblogic.transaction.internal.ServerTransactionImpl.rollback(ServerTransactionImpl.java:375)
         at weblogic.servlet.internal.ServletResponseImpl.abortActiveTx(ServletResponseImpl.java:1424)
         at weblogic.servlet.internal.ServletResponseImpl.send(ServletResponseImpl.java:1390)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1368)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
    >
    I tried with RUNTIME=TRACE logging, but the only thing I see is that AutoGenerated values are fetched and that the sequence (it's really a sequence table) is updated, that all.
    The really strange thing is that all data that should be in the database is there, but the server just prints exceptions into the log. Our customers will think that something is wrong when the log is full of exceptions, so I tried to shut up KODO by setting kodo.Log = none, unfortunately this did not help at all (well the trace stuff is gone, but not the exceptions)
    I tried the exact same code using different application server and database combinations (even different GenerationTypes) and here are my results:
    JBoss:   PSQL  MYSQL  ORCL
    AUTO:     OK    OK     OK
    TABLE:    OK    OK     OK
    IDENTITY: OK    OK     OK
    SEQUENCE: OK    NS     OK
    SUN V9:   PSQL  MYSQL  ORCL
    AUTO:     NOK   NOK     OK
    TABLE:    OK    NOK     OK
    IDENTITY: OK    OK      OK
    SEQUENCE: OK    OK      OK
    WLS 10:   PSQL  MYSQL  ORCL
    AUTO:     NOK    OK     NOK
    TABLE:    NOK    NOK    NOK
    IDENTITY: OK     OK     NOK
    SEQUENCE: NOK    NOK    NOKOK: All is well, no exceptions and all data in DB
    NOK: Exceptions, DB not OK
    NS: Not supported
    Does anyone have an idea what I could try to get rid of the Exceptions?
    Thanks for your help.

  • Connection pooling in multithreaded app results in occasional "Closed Statement" exc"

    Hi there,
    I'm writing a CORBA servant, which amongst all calls in a stored procedure. I'm using connection pooling (just by example) from multiple threads and use grabbed connection to prepare an SP statement, execute it, and close both statement and connection (to return it to the pool). My stress tests run fine for the most part but once in a while throws out "Closed Statement" exception when trying to excecute the prepared statement.
    The reference platform is Solaris7, thin driver 8.1.6 for Java2, jdk 1.2.2, Oracle 8.1.5 (backend), ORBacus 3.3 (external application orb).
    Do you guys have any "multithreaded" statements as far as pooling concerned? Let me know if you need code, schema, anything at all. Any recommendations are greatly appreciated too, like "don't use prepared statements, don't use pooling from multiple threads, download upgrade, etc". Thanks ahead.
    Yours,
    -Evgeni

    Dear Oracle JDBC Development Team,
    First of all, I object to your comment "Please don't spread wrong information.". I do not spread wrong information. That is why I wrote in my previous email, "it isn't thread safe (as far as my tests have shown)". My statement is thus conditional on MY testing. I recognise the fact that I could be wrong. Hence, the conditional clause.
    As for the claim that OracleConnectionCacheImpl is thread safe - well, since it is your software then all I can do is believe you. However, I repeatedly get a java.util.EmptyStackException from calls to oracle.jdbc.pool.OracleConnectionCacheImpl.getConnection() when running my test WITHOUT using the "synchronized" clause on the OracleConnectionCacheImpl object.
    This, of course, could be due to the fact that my test is faulty. I don't know. I can't see the fault in any case. If you can help me with this then I would be more than grateful.
    In any case, when I use the "synchronized" statement on OracleConnectionCacheImpl then this error disappears in a multithreaded environment.
    Another interesting thing my test showed was that the JDBC driver seems to hang under heavy workload. Again, I could be WRONG. It could be my test that causes the problem, however, it is very hard to pinpoint the problem.
    I would really appreciate help with this, if you have time, as we are using OracleConnectionCacheImpl in a major Internet billing system. If you wish to help then please send me an email to [email protected] (or [email protected]) and I will then send you my source code for the test.
    In any case, I will word my messages with even more care in future!
    regards,
    Alexander Day
    null

  • Multithreaded write support in Master

    1. We have an design where in we write synchronously at the master level. Since it is
    bottleneck to usesynchronous write in a multithreaded environment. We have removed the
    synchronous write,
    which lead to too many DB_LOCK_NOTGRANTED Exception at master.
    Note: write transaction timeout = 10secs ( which is too high)
    Below PseudoCode will help in understanding above point.
    HttpController
    requestHandler()
         synchronous
         adapter.write(entity);
         //the adapter writes data to master inside a transaction with timeout value
    10secs.
    The questions are
    a) Does BDB support multithreaded write at master?
    b) If yes, is it something configurable?
    2. In our new design, we have created an asynchronous threads(3 threads with queuecapacity of
    20k) at the master level. 8-13 Replica(In production will have asynchronous threads(3 threads
    with queuecapacity of 200k). What is the optimum number of threads that we can have at the
    master level and queueCapacity?
    For eg.
    HttpController
    requestHandler()
         aynchronousthreadexecutor.execute(entity, adapter);
         //asynchronous thread with 3 threads, 20k queueCapacity     
    }

    Corrigendum: Added information about BDB Version and few more helping information for this context.
    Hi There,
    We have the following questions w.r.t Multi threaded write at master.
    1. We have an design where in we write synchronously at the master level. Since it is bottleneck to
    use synchronous write in a multithreaded environment we have removed the synchronous write,
    which lead to too many DB_LOCK_NOTGRANTED Exception at master.
    Note: write transaction timeout = 10secs ( which is too high)
    Below PseudoCode will help in understanding above point.
    HttpController
    requestHandler()
         synchronous
         adapter.write(entity);
         //the adapter writes data to master inside a transaction with timeout value 10secs.
    The questions are
    a) Does BDB support multithreaded write at master?
    b) If yes, is it something configurable?
    2. In our new design, we have created asynchronous threads(3 number with queuecapacity of 20k) at the
    master level. Replica will have asynchronous threads(3 number with queuecapacity of 200k). In Production Replica count could
    go upto 13.
    a) What is the optimum number of threads that we can have at the master level
    b) What would be ideal value qeueCapacity for the Executor (we use Spring Thread Executor)?
    For eg.
    HttpController
    requestHandler()
         aynchronousthreadexecutor.execute(entity, adapter);
         //asynchronous thread with 3 threads, 20k queueCapacity     
    Thanks.

  • Problem while using SocketChannel in multithreading fashion.

    Hi,
    I want to build a program which establishes the connection between peers and transfer data in multithreaded environment.
    Earlier i used to obtain the socket in the following fashion.
    Socket obtained from ip and port:
    Socket sock = new Socket(ip1, port1);Now i use SocketChannel to obtain the socket in the following fashion.
    SocketChannel sock        
      socket = sock.socket();Problem:
    First peer is performing handshake with another peer which establishes the connection which is done in single threaded fashion which works fine. But after that reading and writting splits into 2 different threads. Now i am able to write data on the output stream but the reading thread gets stuck on a call to readInt() .
    It gives IOException after some time but when i try to print the exception message via ex.getMessage(), it returns null.
    All these works fine in single threaded environment for socket extracted from SocketChannel.
    And also works fine for multiple thread with the socket extracted in the former fashion.
    Can anyone please tell me is there any problem in using socket returned by SocketChannel.socket() in multithreaded fashion?
    Thanx
    Adeesh Jain

    (1) Why are you using a SocketChannel? There is no benefit in blocking mode if you're just going to keep using the streams of its Socket.
    (2) Unlike the streams you get from a directly created Socket, the streams you get from a SocketChannel.socket() are mutually synchronized against simultaneous reading and writing. Does that explain anything?

  • [Problem] About : Dbc Retrieve Data in MultiThread

    Hello,
    Our BDB version is 4.0.14 and 4.2.52.
    We create our JNI by using BDB C++ API. Under multi-processor,
    multithread environment, we do the following operations in the
    same Java process:
    Db->open()
    Dbc->get()
    Dbc->put()
    Db->close()
    After running for 2 hours, when we try to retrieve the data
    by using Dbc->get(), it returns error code [DB_NOTFOUND].
    In the meantime, another process calls Db->open() and Dbc->get()
    and works correctly, without returning any error code.
    Would you please tell us how to solve this problem.
    Thank you very much.

    HI,
    Db->open()
    Dbc->get()
    Dbc->put()
    Db->close()
    After running for 2 hours, when we try to retrieve the data
    by using Dbc->get(), it returns error code [DB_NOTFOUND].
    In the meantime, another process calls Db->open() and Dbc->get()
    and works correctly, without returning any error codeYou didn't explicitly mention using a Berkeley DB environment which is required for multi-threaded and/or multi-process access.
    When you use an environment, resources such as the in-memory cache and locks can be shared by all of the databases opened in the environment. The environment allows you to enable subsystems that are designed to allow multiple threads and/or processes to access DB databases. For example, you use an environment to enable the concurrent data store (CDS), the locking subsystem, and/or the shared memory buffer pool.
    http://www.sleepycat.com/docs/gsg/JAVA/environments.html
    Ron

  • Multithreading java essentials

    hi,
    anybody can suggest me a good book for multi-threading at list from java version 1.5 to 1.6 (new packages util.concurrent etc.)?? I mean, a book without a lot of theory that is, it could explain problems that could be resolved in a multithreading environment with the best right answer algorithm/code used to solve them (with some explanation)
    thank you very much!
    Roby

    I suggest Java Concurrency in Practice http://jcip.net/
    Its an excellent book by one of the key architects of the Concurrency library.

  • Suns LDAP Pool and Multithreading

    I used Suns built in LDAP Pool for quite a while in a multithreaded environment. JDK 1.4.2_08, OpenLdap 2.1.19, Win32.
    Suddenly I have some trouble with it. All pools connections become busy and if that state is reached none is getting free anymore, which locks up my program. I've set the pools logging level to "all" with which I was able to observe how more and more connections get busy until the max connections limit is reached.
    I had had some trouble with the pool. The solution had been to close() each and every JNDI Resource I had requested (NamingEnumerations and Contexts). But now im clueless...
    Anyone who can help with some hints? Are there any rules to observe when using the pool in a multithreaded environment?
    Thanx,
    Peter

    Some more info:
    1. The problem can be reproduced on Java 1.5 and 1.6 (I tried 1.5.0_12 and 1.6.0_01).
    2. Method query() implemented using Netscape LDAP driver works correctly (number of established TCP connections does not exceed 30).
    3. I use Sun LDAP Directory Server 5.2.
    Marek

Maybe you are looking for