Giter VIP home page Giter VIP logo

Comments (6)

capilkey avatar capilkey commented on July 19, 2024

I could be mistaken, but are you sure that the page rendering is multi-threaded? The only potential problem that I can see is if someone tries to load two pages at once.

from senecabbb.

Adam-Sharpe avatar Adam-Sharpe commented on July 19, 2024

I think the problem happens before the rendering occurs. Looking at the exception and stack trace, my understanding of what happens is this:

(Line Numbers referece https://github.com/SenecaCDOT-BigBlueButton/SenecaBBB/blob/master/web-app/src/db/DBAccess.java)

Thread 1: Line 112 executes, and returns a result set with 5 columns (let's say), and assigns it to '_rs'.

Thread 1: Line 113 executes, returns a column count of 5 (DB column counts use base 1 arrays), assigning it to its 'colCount'.

THREAD SWITCH HAPPENS!

Thread 2: Line 112 executes, and returns a result set with 3 columns (let's say). Since the result set variable '_rs' is a shared variable (since both threads are on the same instance of DBAccess), the old result set from thread 1 is overwritten.

... more stuff happens in thread 2, and then

THREAD SWITCH HAPPENS!

Thread 1: Goes about it's business, until it gets to line 117. Then, its colCount is still 5, but its iterating over records with only 3 rows of data (from thread 2). In addition to iterating of the wrong result set, when '_rs.getString(i)' happens with values greater than 3, a null pointer exception is thrown.

Again, because there are so few records in the databases, the queries generally happen quickly, so this is hard to replicate, but with more records it might be easier to see.

from senecabbb.

capilkey avatar capilkey commented on July 19, 2024

By "page rendering" I meant the step where the JSP file is turned into an HTML page before being sent to the user. I'm pretty sure each page only has one thread because the JSP file runs sequentially. There's a threading issue if more than one page is loaded at the same time because each will access the database, but if you were just loading one at a time I don't think threads are the cause of your exception.

from senecabbb.

Adam-Sharpe avatar Adam-Sharpe commented on July 19, 2024

You are right that JSP scriptlets each have there own thread, but the DBAccess class is session-scoped, meaning that it can be shared by multiple requests that belong to the same session.

After looking around some more, I am sure that I am right. I tested it by causing the DBAccess to wait for some period of time after each row was parsed, making it more likely that the threads for each request would get switched out, and trip each other up. It consistently reproduced the error. After making the variables local, or synchronizing the method, the problem disappeared. I will push my fix.

from senecabbb.

amolbhanushali avatar amolbhanushali commented on July 19, 2024

Hello Adam,

I am also facing similar problem.

Could you kindly help me to understand and fix the issue with below details

  1. I have db helper class where static getdbconnection method is defined.
  2. All the methods in db helper class is static.
  3. All the db query methods are defined in this class which will be called by Servlets.

After making the variables local, or synchronizing the method, the problem disappeared.

which variables you have made local and which method you have made synchronized?

from senecabbb.

amolbhanushali avatar amolbhanushali commented on July 19, 2024

Hello Adam,

Got the fix.
PreparedStatement, dbConnection and Resultset all changed to local variable for methods and my application works without any issues.

from senecabbb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.