Single threaded servlet

I need to connect to the database which has to handle multiple requests. So the best approach is to use single threaded servlet using pool of servlet instances.I read the document of single threaded servlet.I ahve gone through the code. here is the code given below:
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SingleThreadConnection extends HttpServlet
implements SingleThreadModel {
Connection con = null; // database connection, one per pooled instance
public void init() throws ServletException {
// Establish the connection for this instance
try {
con = establishConnection();
con.setAutoCommit(false);
catch (SQLException e) {
throw new ServletException(e.getMessage());
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
try {
// Use the connection uniquely assigned to this instance
Statement stmt = con.createStatement();
// Update the database any number of ways
// Commit the transaction
con.commit();
catch (SQLException e) {
try { con.rollback(); } catch (SQLException ignored) { }
public void destroy() {
if (con != null) {
try { con.close(); } catch (SQLException ignored) { }
private Connection establishConnection() throws SQLException {
// Not implemented. See Chapter 9.
i need to know the code of establish connection. In my point of view,is it the database connection code or connection pool.But iam sure it cannot be connection pool.
Can you clear me with the code of how to establish the connection?
thanks in advance.

Preethi05 wrote:
private Connection establishConnection() throws SQLException {
// Not implemented. See Chapter 9.
i need to know the code of establish connection. In my point of view,is it the database connection code or connection pool.But iam sure it cannot be connection pool.
Can you clear me with the code of how to establish the connection?My guess is its the connection pool here, its a guess though. Also its mentioned there to see chapter 9, that might say something.
regards,'
a_joseph

Similar Messages

  • Regarding single threaded servlet

    why pool of instances for single threaded servlet?

    why pool of instances for single threaded servlet
    the container instantiates the servlet when it starts up or when the first request for that servlet comes, instantiation takes place only once.
    when the request comes for a servlet, the container create a thread and gives it response and request object , when another request comes in it creates a thread and gives it request and response object, this process goeson..

  • Single Threaded Model JSP- Servlet

    Servelts can be set to have thread safe access (Single thread model). However, when a JSP is converted in to a servlet, is the servlet tagged as to use the single thread model?

    As of JSP specification 1.2 the default value for the "isThreadSafe" attribute of the page directive is true indicating that the container can direct multiple requests to the page simultaneously. If this value is set to false then the requests will be sent one at a time.
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems inc
    http://www.sun.com/developers/support

  • Help! My application uses a Single Thread !

    Hi all !
    I have a web application which performs some long running tasks. This can be easily simulated with:
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              System.out.println("Started Long Running Task!");
              try {
                   Thread.sleep(20000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("Done");
    In order to deal with Long Running Tasks, I have created a WorkManager with MinThreads 10 and MaxThreads 100
    Then I have assigned the Work Manager to the Web application usign weblogic.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
    <wl-dispatch-policy>WorkManager-0</wl-dispatch-policy>
    </weblogic-web-app>
    However it seems that the Web application uses a SINGLE Thread to reply to the Servlet. In other words issuing n parallel requests the output is:
    Started Long Running Task!
    [20 Seconds Pause]
    Started Long Running Task!
    [20 Seconds Pause]
    Started Long Running Task!
    [20 Seconds Pause]
    Started Long Running Task!
    [20 Seconds Pause]
    My settings are the default Weblogic 12c Server settings, I've just added Weblogic NIO performance libs to the Java's path.
    Is there any setting which allow just 1 Socket for my application ? Maybe it's because I'm using the "unlicensed" (free download) server version ?
    Thanks a lot
    Frank

    You need to create separate Windows user accounts if you want to seperate the behaviour of iTunes for each user. That also means separate iTunes libraries for each user.
    Windows is a multi-user operating system but you are not using it properly. iTunes is not a multi-user application. No application is. You can't expect it to treat different users differently when they are all using the same computer user account.
    Do you understand what I mean?

  • RE: DBSessions and Single-threading

    Thanks Linh. Always good to here from you.
    thanks
    ka
    Kamran Amin
    Forte Technical Leader, Core Systems
    (203)-459-7362 or 8-204-7362 - Trumbull
    [email protected]
    From: Linh Pham[SMTP:[email protected]]
    Sent: Friday, November 13, 1998 2:51 PM
    To: Ajith Kallambella M; [email protected]; ForteUsers;
    [email protected]
    Subject: RE: DBSessions and Single-threading
    all,
    This information (technote draft # 11716) is to clear up the confusion
    regarding
    database access.
    Note, Forte reserves the right to change this implementation in the
    future.
    Currently, there are two flavors of database access available with forte
    (as of version 30j1):
    1. single-threading access to all databases on all UNIX & VMS platforms
    2. multithreading access to all supported database except Sybase on
    intel/alpha-NT,
    and to a certain extent, limited support with SQLServer (see more
    details below)
    1. single-threading access:
    with this type of access, when the following code is executed
    (SQL select ... on MyDBSession;), forte locks the partition and
    all EXTERNAL requests will be queued. However, task switching inside
    the partition continues until the called task enters the DBVendor's
    API (as with any 3GL call). Prior to this moment, you can still have
    multiple tasks running inside the partition. As the called task
    enters the 3GL, it truly blocks a partition, ie. it's OUT there
    talking to the database and not communicating with the
    the forte's environment. If the query is long, the partition might not
    be
    able to acknowledge the environment manager's ping, and thus, will be
    deemed NOT reachable, and a new partition will be started (see technote
    11147). Another problem arises when you have multiple INTERNAL tasks
    trying to perform database access concurrently on the same DBSession.
    Since the behavior is unpredictable, we RECOMMEND that you only
    have ONE task at any time accessing the DBSession inside a partition.
    Please see also technote 7104 for more information regarding DBSession
    sharing & blocking.
    2. multi-threading access:
    on NT, we have added code to allow multithreading access to most
    supported
    database. What does this mean?
    a. when a task access the database, the partition will NOT be blocked.
    b. you can have multiple DBSessions inside a partition and allow
    concurrent access; however, we still RECOMMEND that you
    only have ONE task accessing a DBSession at any one time.
    Please consult a Forte consultant or a TSR in reference to technote
    11151 (only available internally). Please do NOT call Forte Technical
    Support for this technote.
    As to SQLServer, the ODBC driver that you use to access the database
    will
    determine if it's is reentrant or not. There is also a known problem
    with
    the Microsoft ODBC driver which causes the cursor state to become
    invalid when
    multiple tasks accessing the same session. Due to these problems, forte
    recommends that you single-threading access to SQLServer; otherwise
    use at YOUR OWN RISK.
    Hope this helps. IF you have questions regarding multithreading access
    support
    in the future, please contact a Forte Sales Rep or TSR.
    linh ...
    -----Original Message-----
    From: [email protected]
    [<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of Ajith Kallambella M
    Sent: Friday, November 13, 1998 9:08 AM
    To: [email protected]; ForteUsers; [email protected]
    Subject: RE: DBSessions and Single-threading
    Though, the DBSession partitions can reside on a
    thread-safe
    OS ( like NT ), the DBSession is still single threaded
    and your
    partition gets blocked for the duration of the DB
    access. Same
    is true, even if you have multi-threaded databases.
    Forte has not changed DBSession to make it
    multi-threaded.
    Infact, given the current implementation, the only way
    to simulate
    concurrent database access is to replicate the
    partition which
    has DBSession object. The famous DBEntityManagerPattern
    does essentially the same.
    I think we should all feel happy with this now, and
    hope for
    something better in 4.0.
    Ajith Kallambella. M
    Forte Systems Engineer,
    International Business Corporation
    -----Original Message-----
    From: Eric Pereira [<a href=
    "mailto:[email protected]">mailto:[email protected]</a>]
    Sent: Friday, November 13, 1998 9:54 AM
    To: [email protected]
    Cc: [email protected]
    Subject: RE: DBSessions and Single-threading
    Kamran,
    That's not entirely correct. Partitions which access
    multi-threaded
    databases (like MS SQL Server on NT) do not block.
    There was some
    discussion about this over the User Group a while back
    - with no real
    conclusion, so perhaps Forte might want to step in and
    clarify.
    What I'm curious about is the outcome in a situation
    where one DB
    Session accesses SQL Server and another one talks to a
    non
    multi-threaded database within the same partition.
    Thanks.
    Eric Pereira
    Forte Consultant
    ----Original Message Follows----
    From: "Amin, Kamran" <[email protected]>
    To: [email protected], Peter Kelly
    <[email protected]>
    Subject: RE: DBSessions and Single-threading
    Date: Fri, 13 Nov 1998 07:52:09 -0500
    Reply-To: "Amin, Kamran" <[email protected]>
    Peter,
    If one of the service object is being used the that
    partition gets
    blocked until it has finished the request to the
    dbsession. It will not
    mater if the service objects are connected to different
    database. Using
    a
    dbsession makes the partition single threaded and
    that's why we use load
    balancing. Please look at tech. note 10647 for more
    info.
    ka
    Kamran Amin
    Forte Technical Leader, Core Systems
    (203)-459-7362 or 8-204-7362 - Trumbull
    [email protected]
    From: Peter Kelly[SMTP:[email protected]]
    Sent: Friday, November 13, 1998 6:27 AM
    To: [email protected]
    Subject: DBSessions and Single-threading
    Does a DBSession executing in a partition cause thatpartition to
    become
    single-threaded?
    Suppose a partition has 2 Service Objects.
    Each Service Object has its own unique DBSession.
    While a method in one Service Object is using itsDBSession,
    do all other threads in that partition halt and thenresume
    when the work with the first DBSession is complete.
    What if the two DBSessions are connected to differentdatabases,
    does this change anything?
    I heard rumours that Oracle on NT supportedmulti-tasking and blocking
    would not occur. If blocking does occur, is it aForte or Oracle
    limitation?
    Any input/comments appreciated.
    thanks,
    Peter
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive
    <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >>
    Get Your Private, Free Email at <a href=
    "http://www.hotmail.com">http://www.hotmail.com</a>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive
    <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>

    Thanks Linh. Always good to here from you.
    thanks
    ka
    Kamran Amin
    Forte Technical Leader, Core Systems
    (203)-459-7362 or 8-204-7362 - Trumbull
    [email protected]
    From: Linh Pham[SMTP:[email protected]]
    Sent: Friday, November 13, 1998 2:51 PM
    To: Ajith Kallambella M; [email protected]; ForteUsers;
    [email protected]
    Subject: RE: DBSessions and Single-threading
    all,
    This information (technote draft # 11716) is to clear up the confusion
    regarding
    database access.
    Note, Forte reserves the right to change this implementation in the
    future.
    Currently, there are two flavors of database access available with forte
    (as of version 30j1):
    1. single-threading access to all databases on all UNIX & VMS platforms
    2. multithreading access to all supported database except Sybase on
    intel/alpha-NT,
    and to a certain extent, limited support with SQLServer (see more
    details below)
    1. single-threading access:
    with this type of access, when the following code is executed
    (SQL select ... on MyDBSession;), forte locks the partition and
    all EXTERNAL requests will be queued. However, task switching inside
    the partition continues until the called task enters the DBVendor's
    API (as with any 3GL call). Prior to this moment, you can still have
    multiple tasks running inside the partition. As the called task
    enters the 3GL, it truly blocks a partition, ie. it's OUT there
    talking to the database and not communicating with the
    the forte's environment. If the query is long, the partition might not
    be
    able to acknowledge the environment manager's ping, and thus, will be
    deemed NOT reachable, and a new partition will be started (see technote
    11147). Another problem arises when you have multiple INTERNAL tasks
    trying to perform database access concurrently on the same DBSession.
    Since the behavior is unpredictable, we RECOMMEND that you only
    have ONE task at any time accessing the DBSession inside a partition.
    Please see also technote 7104 for more information regarding DBSession
    sharing & blocking.
    2. multi-threading access:
    on NT, we have added code to allow multithreading access to most
    supported
    database. What does this mean?
    a. when a task access the database, the partition will NOT be blocked.
    b. you can have multiple DBSessions inside a partition and allow
    concurrent access; however, we still RECOMMEND that you
    only have ONE task accessing a DBSession at any one time.
    Please consult a Forte consultant or a TSR in reference to technote
    11151 (only available internally). Please do NOT call Forte Technical
    Support for this technote.
    As to SQLServer, the ODBC driver that you use to access the database
    will
    determine if it's is reentrant or not. There is also a known problem
    with
    the Microsoft ODBC driver which causes the cursor state to become
    invalid when
    multiple tasks accessing the same session. Due to these problems, forte
    recommends that you single-threading access to SQLServer; otherwise
    use at YOUR OWN RISK.
    Hope this helps. IF you have questions regarding multithreading access
    support
    in the future, please contact a Forte Sales Rep or TSR.
    linh ...
    -----Original Message-----
    From: [email protected]
    [<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of Ajith Kallambella M
    Sent: Friday, November 13, 1998 9:08 AM
    To: [email protected]; ForteUsers; [email protected]
    Subject: RE: DBSessions and Single-threading
    Though, the DBSession partitions can reside on a
    thread-safe
    OS ( like NT ), the DBSession is still single threaded
    and your
    partition gets blocked for the duration of the DB
    access. Same
    is true, even if you have multi-threaded databases.
    Forte has not changed DBSession to make it
    multi-threaded.
    Infact, given the current implementation, the only way
    to simulate
    concurrent database access is to replicate the
    partition which
    has DBSession object. The famous DBEntityManagerPattern
    does essentially the same.
    I think we should all feel happy with this now, and
    hope for
    something better in 4.0.
    Ajith Kallambella. M
    Forte Systems Engineer,
    International Business Corporation
    -----Original Message-----
    From: Eric Pereira [<a href=
    "mailto:[email protected]">mailto:[email protected]</a>]
    Sent: Friday, November 13, 1998 9:54 AM
    To: [email protected]
    Cc: [email protected]
    Subject: RE: DBSessions and Single-threading
    Kamran,
    That's not entirely correct. Partitions which access
    multi-threaded
    databases (like MS SQL Server on NT) do not block.
    There was some
    discussion about this over the User Group a while back
    - with no real
    conclusion, so perhaps Forte might want to step in and
    clarify.
    What I'm curious about is the outcome in a situation
    where one DB
    Session accesses SQL Server and another one talks to a
    non
    multi-threaded database within the same partition.
    Thanks.
    Eric Pereira
    Forte Consultant
    ----Original Message Follows----
    From: "Amin, Kamran" <[email protected]>
    To: [email protected], Peter Kelly
    <[email protected]>
    Subject: RE: DBSessions and Single-threading
    Date: Fri, 13 Nov 1998 07:52:09 -0500
    Reply-To: "Amin, Kamran" <[email protected]>
    Peter,
    If one of the service object is being used the that
    partition gets
    blocked until it has finished the request to the
    dbsession. It will not
    mater if the service objects are connected to different
    database. Using
    a
    dbsession makes the partition single threaded and
    that's why we use load
    balancing. Please look at tech. note 10647 for more
    info.
    ka
    Kamran Amin
    Forte Technical Leader, Core Systems
    (203)-459-7362 or 8-204-7362 - Trumbull
    [email protected]
    From: Peter Kelly[SMTP:[email protected]]
    Sent: Friday, November 13, 1998 6:27 AM
    To: [email protected]
    Subject: DBSessions and Single-threading
    Does a DBSession executing in a partition cause thatpartition to
    become
    single-threaded?
    Suppose a partition has 2 Service Objects.
    Each Service Object has its own unique DBSession.
    While a method in one Service Object is using itsDBSession,
    do all other threads in that partition halt and thenresume
    when the work with the first DBSession is complete.
    What if the two DBSessions are connected to differentdatabases,
    does this change anything?
    I heard rumours that Oracle on NT supportedmulti-tasking and blocking
    would not occur. If blocking does occur, is it aForte or Oracle
    limitation?
    Any input/comments appreciated.
    thanks,
    Peter
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive
    <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >>
    Get Your Private, Free Email at <a href=
    "http://www.hotmail.com">http://www.hotmail.com</a>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive
    <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>

  • Waiting for a mouse click in a single thread

    Here's my problem:
    I'm working on a program I didn't initially create, and I picked it up from the rough midpoint of its evolution. It is a single thread AWT program, with a mouseListener interface already implemented.
    Here's my problem. In a game setting, we have two players. It is no problem when both are computer controlled. When player one is controlled by a human, I need to wait for a mouse event before returning, because upon returning player two moves (regardless of its player configuration).
    I can't do any kind of busy waiting because it is a single thread. I'm looking for some kind of option besides making the program multithreaded. This also makes it difficult to use some sort of boolean variable, though I don't think it's impossible.
    Thanks in advance for any help.
    Eric

    #9 - You are correct in your assumptions. I agree it's
    not the best model, but it worked for the original
    purpose, which was to have one player always
    controlled by the computer, and the option of
    selecting a second player as being either human or
    computer. Since each move is made manually - that is,
    for a move to be made, it requires user input - there
    was no harm in returning from a function, because it
    had no immediate computation. The requirements have
    just changed, and now I must allow both players to be
    selectable. This presents a problem in that I have to
    wait for the move actions to finish before
    proceeding.Understood.
    >
    My only question is, how can I access the AWT thread?You mentioned in an earlier post that you have action listeners. As triggered by user events, these are always called on the AWT thread. For example:
    import javax.swing.*;
    import javax.awt.event.*;
    JButton button = new JButton( new AbstractAction {
            public void actionPerformed(ActionEvent e) {
                synchronized (myMonitor) {
                    myMonitor.notifyAll();
        });This button can be added to some swing UI. If clicked on, then actionPerformed will be called on the AWT thread, and any threads waiting on myMonitor will be notified.
    I see what you are saying - it's almost exactly what
    my coworkers told me - but I don't have the knowledge
    to implement it, which is why I'm here. Creating a
    monitor object isn't a problem (makeMove() would need
    to be synchronized, otherwise you wouldn't be able to
    call wait()),I recommend using a separate object for the monitor, especially if you are already using synchronized, so that you know exactly how each object's lock is being used. If you're sure it is safe, then there is nothing wrong with using the object itself as the monitor, as you suggest, however.
    but I'm not sure what you mean by the
    action handling method should be called on the AWT
    thread.Just that any action listener method is always called on the AWT thread in response to user action.
    Dave

  • I have a doubt about The Single-Thread Rule

    The [url http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html#rule]Single Thread Rule states:
    Rule: Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread.
    I began to wonder about this because so much code seems to work just fine when it isn't executed in the event dispatching thread. Why are there exceptions? I went looking for some code which acted differently when executed on the event thread than when it was not. I found this
    http://forum.java.sun.com/thread.jsp?forum=57&thread=410423&message=1803725#1803725
    Now I started wondering why this was the case. What I found was that DefaultCaret adds a document listener to the document of the JTextComponent. In this listener, the insertUpdate() method specifically tests if it is running on the event dispatch thread and if it is, it updates the caret position.public void insertUpdate(DocumentEvent e) {
        if (async || SwingUtilities.isEventDispatchThread()) {
            // ... update the caret position ...
    }I then copied the code from DefaultCaret and made a MyCaret. I needed to tweek the code a little bit, but it ran. I removed the event thread test. It worked outside the event thread. There was a small difference in the results though. The textarea did not scroll all the way to the bottom. Almost, but not quite. I didn't test enough to make sure this was the only problem, but there was at least one problem.
    Now I started think about why this would be. The thought crossed my mind that the order of the events which were posted to the event queue were probably important. Sun found bugs when components were updated out of the event thread, so they essentially ignored events which weren't on the event thread and created the The Single-Thread Rule.
    A few days pass. I'm starting to wonder if Sun could have done a better job making Swing components thread safe. I also don't know that this specific case I found was the rule or the exception to the rule. But without insight into the design philosopy of Swing, I would have to examine all their components and see how they have written them and see if I can come up with a better design. That sound like a lot of work. Especially without getting paid for it.
    But wait a second, all you have to do is call the append() method of JTextArea on the event thread. If that is the case, why didn't they write the freakin component that way? Well, I'll try itclass MyTextArea extends JTextArea {
      public MyTextArea(int rows, int columns) { super(rows,columns); }
      public void append(final String text) {
        if (SwingUtilities.isEventDispatchThread()) super.append(text);
        else {
          SwingUtilities.invokeLater(new Runnable() {
            public void run() { myAppend(text); }
      private void myAppend(String text) { super.append(text); }
    }I change [url http://forum.java.sun.com/thread.jsp?forum=57&thread=410423&message=1803725#1803725]camickr's code to use a MyTextArea and it works fine without calling from the event thread. I've essentially moved The Single-Thread Rule to the component itself rather than relying on each and every one of the [url http://www.aboutlegacycoding.com/default.htm?AURL=%2FSurveys%2FSurvey6intro%2Easp]2.5 million Java programmers worldwide to use SwingUtilities.invaokeLater().
    Now for my question...
    Why didn't Sun do this?

    Swing is slow enough as it is. Lets not make it slower
    just
    because dense "programmers" don't know what they are
    doing.I agree with you in defending the current model, but aren't you a bit harsh there?!? ;-)
    Well, there are a number of not-so-dense programmers that expect such high-level components to be thread-safe. The question is worth asking whether Sun intentionally favor the explicit thread management for performance reasons, or whether this was an oversight.
    I'd go for the former (intentional) : indeed any GUI toolkit is inherently thread-based; there is always a distinction between the graphical thread(s) and the application threads - and the programmer always has to manage explicit thread creation to handle long-running event handlers without blocking the event dispatching thread. Extending thread concerns to the updating of components is therefore not a big move.
    So it seems fair that a core GUI toolkit does not hide thread issues (though to the best of my knowledge there is no such limitation in updating AWT components), or at least that's what Sun deemed.
    An ease-of-use-focused toolkit wrapping the core toolkit for thread-safety can be provided as a third-party product. Though I agree that wrapping the dozens of existing widgets and hundreds of methods is cumbersome - and the lack of such products probably shows it would have a low added value to trained developpers.
    Because your way is an extra method call and if
    statement, neither of which is necessary if you already know you
    are in the correct thread. Now count the number of methods
    which will need to be changed (and add up the extra cost).Indeed it's quite common to update several properties of several widgets in one bulk (when user clicks "OK", add a row to the table, change the title of the window, update status bar, re-enable all buttons, change some color,...).
    In this case explicit thread management doesn't spare one if but a dozen of redundant ifs!
    Note that there could have been if-less ways to cope for thread safety, such as creating a copy of the component's model when a change is made to a component, and switching the model only before paint() is called in the event-dispatching - of course coalescing all changes into the same "updated" model until paint() is called.
    But this would trade ease of use for redundant memory consumption, especially for some components with potentially huge models (JTree, JTable, JTextArea,...). And Swing appears to be already quite memory-greedy!

  • Thread: Could not generate the XML in single thread mode

    Hi all,
    I have created a report using PLSQL Procedure method after submitting the request I am getting the following Error.Couldn't sort out why I am getting the error while running the report.
    Error in "Multi threaded or single threaded execution block" of XXRX_REPORT_OUTPUT_PKG.insert_into_nested_table procedure
    ERROR :ORA-20005: Could not generate the XML in single thread mode
    XXRXERROR: XXRX_REPORT_OUTPUT_PKG.run_report SQLERROR: ORA-20005: ORA-20005: Could not generate the XML in single thread mode
    Can someone help me out finding the issue
    Thanks in Advance

    Hi,
    Please read SQL and PL/SQL FAQ
    We cannot guess what is the error if you don't post any part of your code.
    Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • DBMS_PARALLEL_EXECUTE multiple threads taking more time than single thread

    I am trying to insert 10 million records from source table to target table.
    Number of chunks = 100
    There are two scenarios:
    dbms_parallel_execute(..... parallel_level => 1) -- for single thread
    dbms_parallel_execute(..... parallel_level => 10) -- for 10 threads
    I observe that the average time taken by 10 threads to process each chunk is 10 times the average time taken in case of single thread.
    Ideally it should be same which would reduce the time taken by a factor of 10 (due to 10 threads).
    Due to the above mentioned behavior, the time taken is the same in both cases.
    It would be great if anybody can explain me the reason behind such behavior.
    Thanks in advance

    Source Table = TEST_SOURCE
    Target Table = TEST_TARGET
    Both tables have 100 columns
    Below is the code:
    DECLARE
    l_task VARCHAR2(30) := 'test_task_F';
    l_sql_stmt VARCHAR2(32767);
    l_try NUMBER;
    l_stmt VARCHAR2(32767);
    l_status NUMBER;
    BEGIN
    l_stmt := 'select dbms_rowid.rowid_create( 1, data_object_id, lo_fno, lo_block, 0 ) min_rid,
                                       dbms_rowid.rowid_create( 1, data_object_id, hi_fno, hi_block, 10000 ) max_rid
                                       from (
                                       select distinct grp,
                                  first_value(relative_fno)
                                  over (partition by grp order by relative_fno, block_id
                                  rows between unbounded preceding and unbounded following) lo_fno,
                                  first_value(block_id )
                                  over (partition by grp order by relative_fno, block_id
                                  rows between unbounded preceding and unbounded following) lo_block,
                                  last_value(relative_fno)
                                  over (partition by grp order by relative_fno, block_id
                                  rows between unbounded preceding and unbounded following) hi_fno,
                                  last_value(block_id+blocks-1)
                                  over (partition by grp order by relative_fno, block_id
                                  rows between unbounded preceding and unbounded following) hi_block,
                                  sum(blocks) over (partition by grp) sum_blocks
                                  from (
                                  select relative_fno,
                                  block_id,
                                  blocks,
                                  trunc( (sum(blocks) over (order by relative_fno, block_id)-0.01) / (sum(blocks) over ()/100) ) grp
                                  from dba_extents
                                  where segment_name = upper(''TEST_REGION_SOURCE'')
                                  and owner = ''FUSION'' order by block_id
                             (select data_object_id from user_objects where object_name = upper(''TEST_REGION_SOURCE'') )';
    DBMS_PARALLEL_EXECUTE.create_task (task_name => l_task);
    DBMS_PARALLEL_EXECUTE.create_chunks_by_sql(task_name => l_task,
    sql_stmt => l_stmt,
    by_rowid => true);
    l_sql_stmt := 'insert into FUSION.TEST_REGION_TARGET(REGION_ID,REGION1,REGION2,REGION3,REGION4,
                             ...., REGION99
                             SELECT REGION_ID,REGION1,REGION2,REGION3,REGION4,
                             .....,REGION99
                             from FUSION.TEST_REGION_SOURCE WHERE (1=1) AND rowid BETWEEN :start_id AND :end_id ';
    DBMS_PARALLEL_EXECUTE.run_task(task_name => l_task,
    sql_stmt => l_sql_stmt,
    language_flag => DBMS_SQL.NATIVE,
    parallel_level => 10);
    -- If there is error, RESUME it for at most 2 times.
    l_try := 0;
    l_status := DBMS_PARALLEL_EXECUTE.task_status(l_task);
    WHILE(l_try < 2 and l_status != DBMS_PARALLEL_EXECUTE.FINISHED)
    Loop
    l_try := l_try + 1;
    DBMS_PARALLEL_EXECUTE.resume_task(l_task);
    l_status := DBMS_PARALLEL_EXECUTE.task_status(l_task);
    END LOOP;
    DBMS_PARALLEL_EXECUTE.drop_task(l_task);
    END;
    Edited by: 943978 on Jul 2, 2012 9:22 AM

  • The Coded Ui Test Method is runnung in Single Thread Apartment(STA) Mode of COM

    Hi,
    when running tests with CUIT,and after a timeout in the previous tests we noticed the following error:
    lass Initialization method TestSuite2.MyClassInitialize threw exception. Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: The Coded UI Test is running in Single Thread Apartment (STA) mode of COM. In this mode, all the playback calls should happen from the TestMethod thread only and UITestControl should not be shared across TestMethods..
    Stack Trace:
    at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.ThrowExceptionIfCrossThreadAccess(IScreenElement uiElement)
    at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.InitPlayback()
    at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()
    at RapArtTest.Tests.Generic.GenericTestsTemplate.ClassInit(TestContext context)
    at TestSuite2.MyClassInitialize(TestContext context)Please note that we get this error if we have 10 tests failing with a timeout issue previously, after that all our tests suite fail with the same STA error.is there a way to workaround this ?

    Hi kaki2000,
    >>Please note that we get this error if we have 10 tests failing with a timeout issue previously.
    Which VS IDE did you use, VS2010 or high version?
    Do you run your coded UI tests in VS IDE or you add them to a load test? If you run your coded UI tests one by one in VS IDE, how about the result?
    >>The Coded UI Test is running in Single Thread Apartment (STA) mode of COM.  In this mode, all the playback calls should happen from the TestMethod thread only and UITestControl should not be shared across TestMethods..
    After a test method is finished, please call the clean playback. Then the later test method can reload UIMap and find exactly one on testing.
    Reference:
    http://blog.csdn.net/marryshi/article/details/8815025
    https://social.msdn.microsoft.com/Forums/en-US/ea5a2bd0-dbae-4256-b8c3-25d6eb45257a/codedui-single-thread-apartment-sta-mode-of-com-issue?forum=vsautotest
    In addition, do not call UI actions from the ClassCleanup method.
    Reference:
    http://stackoverflow.com/questions/16667350/coded-ui-test-single-thread-apartment-sta-error-occurred-while-executing-clas
    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites;
    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to improve spreadsheet speed when single-threaded VBA is the bottleneck.

    My brother works with massive Excel spreadsheets and needs to speed them up. Gigabytes in size and often with a million rows and many sheets within the workbook. He's already refined the sheets to take advantage of Excel's multi-thread recalculation and
    seen significant improvements, but he's hit a stumbling block. He uses extensive VBA code to aid clarity, but the VB engine is single-threaded, and these relatively simple functions can be called millions of times. Some functions are trivial (e.g. conversion
    functions) and just for clarity and easily unwound (at the expense of clarity), some could be unwound but that would make the spreadsheets much more complex, and others could not be unwound. 
    He's aware of http://www.analystcave.com/excel-vba-multithreading-tool/ and similar tools but they don't help as the granularity is insufficiently fine. 
    So what can he do? A search shows requests for multi-threaded VBA going back over a decade.
    qts

    Hi,
    >> The VB engine is single-threaded, and these relatively simple functions can be called millions of times.
    The Office Object Model is
    Single-Threaded Apartments, if the performance bottleneck is the Excel Object Model operation, the multiple-thread will not improve the performance significantly.
    >> How to improve spreadsheet speed when single-threaded VBA is the bottleneck.
    The performance optimization should be based on the business. Since I’m not familiar with your business, so I can only give you some general suggestions from the technical perspective. According to your description, the size of the spreadsheet had reached
    Gigabytes and data volume is about 1 million rows. If so, I will suggest you storing the data to SQL Server and then use the analysis tools (e.g. Power Pivot).
    Create a memory-efficient Data Model using Excel 2013
    and the Power Pivot add-in
    As
    ryguy72 suggested, you can also leverage some other third party data processing tool
    according to your business requirement.
    Regards,
    Jeffrey
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • EOIO vs single thread

    I have a scenario,
    R3>IDoc(EOIO Queue)-->BMP(...do something there after), we set up the EOIO queue by Idoc serialization(add a line to idxquque table),  the problem is:
    we send multiple idocs at the exactly the same time(same second), the order they finish at the BPM is not the same as the sequence they're is sent out.
    My question is, how can the sequence mixed up? is EOIO single thread? and how do I keep the Idoc process exactly the same sequence?

    Hi, Moorthy,
    Glad to see you here again.
    I just saw the note 833740. According to the note
    "The BPE acts as an application system within the Integration Server and, on the arrival side, supports the service grade EOIO. On the output side, however, it must be assumed that the BPE will communicate with several business systems, for which the service grade EOIO can only be adhered to for specific applications."
    My problem is at the time when the idocs go through EOIO queue and arrive at the BPM, the order has already changed. And according to the note, BPE should support EOIO at arrival side. Any more thought?
    Thanks

  • Several handles to the same database in a single thread

    I have a single-threaded program where several db handles are created with db_create() and they're all opened to the same database in the same file. The handles will be used serially, in quite random order for reads and writes, and each of them will be closed at the end of the program.
    Do I need to take any steps to ensure the integrity of the database? I currently create the handles and open the databases with the default settings, if applicable.

    Guys, I am still racking my brain. I have taken some screenshots to show you how I have my database tables set up. I was able to get the tables over to the InnoDB type so I can make foreign keys. Here is how I currently have them setup, can someone check this out and see if it's correct?
    Table 1 (carinfo)
    Table 2 (images)
    Thanks

  • Minimal single threaded web server?

    Is there a library or code samples to implement a minimal, single threaded server for accepting and responding to HTTP GET/POST requests?
    What I want to do is to accept a GET or POST request, run my own code which calculates something and send that back to the client as a response. The server only needs to accept and process one request at a time (the HTTP protocol is just used to make the interaction between a perl-written client and the Java algorithm simpler).
    I wonder what the minimum-effort solution to this is.
    PS: Sorry if this really belongs into the newbie-forum ...

    johann_p wrote:
    Is there a library or code samples to implement a minimal, single threaded server for accepting and responding to HTTP GET/POST requests?A library for this existing is rather unlikely, since it is such a small task. There are definitely some samples for this around, maybe Google can lead you to them.
    What I want to do is to accept a GET or POST request, run my own code which calculates something and send that back to the client as a response. The server only needs to accept and process one request at a time (the HTTP protocol is just used to make the interaction between a perl-written client and the Java algorithm simpler).Well, create a ServerSocket, accept that, get the InputStream, wrap it in a Reader, read the first line, check if it's one of the supported methods, read the rest until you get an empty line (i.e. end of request), do your calculation, get the OutputStream, wrap it in a Writer, write out your answer (be sure to include the correct HTTP response + headers).
    But everything (except for creating the ServerSocket) in a endless loop and you're set.
    I wonder what the minimum-effort solution to this is.Pay someone to do it for you.

  • Eliminate thread-switch pipeline stage in single-thread T1?

    I heard this question offline and wanted to post it (and in a moment, a response to it) here, to share it with the community:
    OpenSparc T1's core pipeline consists of six stages: Fetch, Thread-Switch, Decode, Execute, Memory, and Writeback. Is it possible in a single-thread T1 implementatin to remove the Thread-Switch stage, so that the pipeline is only five stages? Since the Switch stage contains a strand instruction register for each strand and the strand scheduler, the current instruction for that strand was issued to the pipe, is it possible to just remove them?

    What I am doing is to develop an instruction-level simulator for the students to get familar with a subset (only key instructions) of SPARC instruction set, demonstrating how the instructions are executed one by one, and how they are executed if pipelined. It is to be used only to the detail level of pipeline stages. They only need to know what is done in each stage, but they don't care how it is implemented.
    ...this system is an independent tool only for teaching purpose... They just write small programs in assembly language, assemble them and then load them to the simulator...
    Now the problem is: Is it better to use a 5-stage model (Fetch, Decode, Execute, Memory, and Writeback) or to use the 6-stage model (Fetch, Switch, Decode, Execute, Memory, and Writeback) , with the Switch doing nothing (instructions just pass through it) ?When you say "simulator", I assume that you mean a purely software simulator, not a processor synthesized from the OpenSPARC T1 RTL (Verilog) design code.
    I believe that the OpenSPARC T1 software simulators included in the OpenSPARC download are pure instruction-set simulators, that execute instructions but do not simulate pipeline stages. So perhaps there is an OpenSPARC pipepline software simulator you are using, or perhaps you are thinking about writing your own pipeline simulator? In that case, it would seem to make sense to use the simpler 5-stage pipeline model. For teaching purposes, there would be no point in including a Switch stage unless you were simulating a multithreaded processor core.

Maybe you are looking for

  • Getting notifications for groups, based on administrator attributes

    We have multiple development teams who want to subscribe to notifications that are relevant to the targets that they use. We also have an operations team that cares only about notifications for production targets involved in batch jobs. What is the a

  • Time Machine Backup No longer available under Lion

    I was having a problem with Time Machine, although I didn't know it until today. It had been going through the backup procedure every day.  But today, I decided to go into Time Machine just to look around. It took several tries but it finally came up

  • Missing fonts in Adobe Reader for Pocket PC

    Hi, I recently installed the Adobe Reader 2.0 on my pocket PC and found that on my documents where bullet points are used it starts to complaint that it misses the font WingDings. I have installed the WinDings font in the Windows\Font directory, but

  • Why photos look warmer in Safari??

    Hi everyone, I am using CS3 on my 2006 white iMac to edit my photos. I adjust the colour temperature of my photos so that they look natural in CS3. However, after posting them on Flickr, they looks much warmer on Safari. If I use FireFox (instead of

  • EJB deployment descriptor

    Hi I have jusr started with the EJB. I am using JBoss Server. I have a session bean and a MessageDrivenBean in the same package. Do I mention both of them in the same ejb-jar.xml file place inside the META-INF directory as follows: <?xml version="1.0