Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Create a webapp around an existing webapp for handling session control

Posted on 2006-04-05
Medium Priority
Last Modified: 2010-04-01

Hi all,

A time ago I posted this question http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21650462.html#15405554

The result of that question was to use tomcat valves. So far so good. In a couple of weeks, I will begin development of the application described in the above question.
I have one reservation left.

Are these Valves thread-safe? Does anyone know about this?

Thank you.
Question by:tcollogne
  • 4
  • 2
LVL 35

Expert Comment

ID: 16378806
I would treat them like servlets, so any static or global members should be handles with care, but otherwise all method level variables should be fine :-)


Author Comment

ID: 16389202
So, I can use private methods inside the class with no problem like this. The getDatabaseUser is a private method that I created. It will get information from inside a database (JDBC).

public class TomcatValveEx extends ValveBase {
   public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException {

             System.out.println("Example VALVE hit");
             context.invokeNext(request, response);

   private String getDatabaseUser() {
      return "test";

LVL 35

Accepted Solution

TimYates earned 200 total points
ID: 16389507
that *should* be ok

Not sure if you can get at the DBCP from inside a valve though...  You're treading new ground as far as my experience goes :-/
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 16411799
I am going to keep this open for a little longer.

Author Comment

ID: 16584415
Indeed, I can't seem to manage getting a DataSource in the valve.
I get a javax.naming.NameNotFoundException : Name comp is not bound in this Context.

I use this code for getting a datasource :

Context initContext = new InitialContext();                        
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)initContext.lookup("jdbc/vtvres");            
Connection conn = ds.getConnection();

Is there another way of achieving it?

Author Comment

ID: 16584421
Sorry the code is

Context initContext = new InitialContext();                  
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/vtvres");            
Connection conn = ds.getConnection();

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question