Shiva Mantri

Greenhorn
+ Follow
since Dec 30, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Shiva Mantri

if isThreadSafe=false, then the servlet container implements SingleThreadModel. What this means is that only one thread(or request) will be able to execute service method of the servlet instance. Depending on the load on the container, the container may choose to initiate multiple intances.
Whats happening in your code is, the container created only one instance and both the requests were handled by the same servlet instance. One request incremented the count of member variablet to 9, and the next request, which was handled by the same instance, so you get from 10-19.
bottomline: SingleThreadedModel doesn't guarantee that you will get a new instance for every request (xref: ServletSpec2.3 - SRV.2.2 or SingleThreadModel interface)
[ November 13, 2003: Message edited by: Shiva Mantri ]
you may want to get a book on web/enterprise application design.
Synchronization results in performance bottleneck. Use it wisely. If too many threads access the contextAttribute, and its synchronized, you may want to think about your design again.
Each object gets its own copy of variables when new instances are created. So, each thread works with its own copy. If you are thinking of displaying something to the screen, like visitCount, which is a member variable, you have to make it static. This way you get uncorrupted visitCount.
[ November 08, 2003: Message edited by: Shiva Mantri ]
Q1. Dont know and not sure about my response. Seems like a web server must process the request within a specified time period, otherwise it will return Request Timeout message (code 408).
Q2.

The pathname must begin with a "/" and is interpreted as relative to the current context root


The path is NOT interpreted relative to current context, but relative to server's document root and is matched against the context roots of other web applications hosted on the container.
Q3. in tomcat, its webapp/ROOT context. you have to specify your servlets even in root context to be picked up, else container wont initialize them. you can access resources without specifying context. eg: http://localhost:8080/test.jsp or http://localhost:8080/testServlet provided you specified testServlet in the deployment descriptor.
Q4. dont know...!!!
Whenever an object is added/removed from session, the container introspects for interfaces implemented by that object. If it implements HttpSessionBindingListener, it calls appropriate method (valueBound/valueUnbound).
Also, for the listeners specified in web.xml, the container creates only one instance for each listener and events from all sessions are sent to the specific listener instance. Whereas, HTTPSessionBindingListener is specific to an Object.
Spec specifies that an object has to be notified, when the object is bound/unbound from/to session. So, containers introspect and notify with HTTPSessionBindingEvent.
-Shiva
Neal,
Please check http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#228745

A compile-time error occurs if an instance method overrides a static method.

. So you have to override with static method only. But in this case, it is called Hiding (continue reading section JLS8.4.6.2).
Hope this helps
-Shiva
moderators/admins, may be you want to add this link to list of mock exams http://www.jdiscuss.com/Enthuse/jsp/ShowAvailableTests.jsp
-shiva
ps: its from another discussion forum. dont know whether it involves copyright things
yes you can, but you will lose the exception information thrown from try clause, unless you log the exception information.


JLS11.3 Handling of an exception
If a try or catch block in a try-finally or try-catch-finally statement completes abruptly, then the finally clause is executed during propagation of the exception, even if no matching catch clause is ultimately found. If a finally clause is executed because of abrupt completion of a try block and the finally clause itself completes abruptly, then the reason for the abrupt completion of the try block is discarded and the new reason for abrupt completion is propagated from there.


[ January 28, 2003: Message edited by: Shiva Mantri ]
Dude.....
new String("ABC") creating two objects is still a mystery to me one in the main memory and one in the pool.
here are contradictory statements regarding String.intern()/new String("ABC"): (lets assume, S=new String("ABC"); is the only statement in the main method).
1. API states

When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.

So, to add a String to the pool, you intern it. Now, if you intern object S, ABC will be added to the pool (assuming new doesn't add ABC to pool when you initialize S).
2. A previous posting on this forum (regarding Kathy and Bert book)
https://coderanch.com/t/240553/java-programmer-SCJP/certification/Kathy-your-book
Kathy's reply:

For the exam, you need to know that IF you use 'new' to create a new String that is not *already* in the pool, TWO String objects are created. But there is no need to ever have duplicates in the String pool, so if the String is already in the pool at the time you use 'new', there will be only ONE created.

If this true, Prashanth and others, I agree answer to the original post would be 1(one). WHY WOULD I EVER NEED TO INTERN A STRING??? just to get a reference from the pool??? Why would API state "Otherwise, this String object is added to the pool and a reference to this String object is returned" ? The string would already be in the pool!!!
-Shiva
PS: JavaRanch webmaster, Can you please make the TextArea for Message field wider in post reply/edit post pages? It is hard to review a message in small TextArea!!!
[ January 28, 2003: Message edited by: Shiva Mantri ]

Originally posted by Shan:
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running


In option b, Running User threads could call System.exit() and terminate the program and JVM. So, I think the answer should be 'e', according to JLS 12.8.
I am wondering about option a: deamon threads can not be destroyed. They can not be???

JLS 12.8 Program Exit
A program terminates all its activity and exits when one of two things happens:
* All the threads that are not daemon threads terminate.
* Some thread invokes the exit method of class Runtime or class System and the exit operation is not forbidden by the security manager.


-Shiva
ps: was reviewing all the old posts regarding threads to test my threads basics
i found this while grazing on the ranch
https://coderanch.com/t/194519/java-programmer-SCJP/certification/ATTENTION-Study-given-rules-Will
[ January 22, 2003: Message edited by: Shiva Mantri ]

b) I am using Jcreator as an IDE. If I use the compile file and execute file options, the program executes. If I use cmd line on Windows
java test (with test in java sdk's bin)
I get an exception
Exception in thread "main" java.lang.NoSuchMethodError: main


JLS12.1: "JVM starts execution by invoking the method main of some specified class". So, when you do java test, test class doesn't have main method, instead Q123.class has the main method. java Q123 will work.
I didn't use Jcreator, but from my experience with JBuilder, it will sift through files in your project for main method/s and locates it in Q123, and it is what Jcreator is using to execute your program. If you have an option to turn on output window, it will show the exact command it is executing. It will show java Q123.
-Shiva
[ January 17, 2003: Message edited by: Shiva Mantri ]
John
I wanted to mention that you may have not pasted code properly, in my previous post. but ignored it.
So, no errata in the book. cooll.. I have RHE book, but want to take a look at Kathy/Bert book. Everybody in this forum are really appreciating it. will check it out. PEACE
Good Luck
-Shiva

snippet from Kathy's book
2 � String s = new String("abc"); // creates two objects, and one
// reference variable
In this case, because we used the new keyword, Java will create a new String
object in normal (nonpool) memory, and s will refer to it. In addition, the literal
�abc� will be placed in the pool.

The question is "using new alone, would JVM place the literal in the pool"? Does new create two String objects?

John Paverd response:
The new operator only creates 1 String object.

This is what I have been assuming, till I encountered this original post. I think this is true and there is errata in the book. If not, we need to be enlightned, with new operator creating two objects.

John Paverd response:
String s1 = "abc";
String s2 = new String("abc");
System.out.println(s1 == s2);
When new String("abc") is executed, Java creates a copy of the "abc" String that is in the literal pool. If that were not so, the preceding code would print true. Run it and you will see that it prints false. False means that s1 and s2 refer to 2 different objects, so there must exist two String objects containing "abc".

I dont disagree with this at all.
[ January 15, 2003: Message edited by: Shiva Mantri ]