Just Sharing Thoughts…

A vision without skill is like a day dreaming…

Thread-safety issue in Servlets

Posted by Vijay Kumar on September 23, 2008

Generally, the thread-safety issue breaks down like this:

Local variables:
thread-safe in any context, servlet or otherwise

Instance variables:
not normally thread-safe, thread safe in servlets implementing the
SingleThreadedModel.  But since as Corey mentions, most containers will
create multiple copies of your servlet (each with it’s own copy of the
instance variables) as simultaneous requests come in, instance variables
become essentially useless for sharing data outside the scope of a single
method call (the main reason they are used in servlets).

Static variables:
not thread-safe.  Even the SingleThreadedModel does not help, since most
containers will again create several copies of your servlet to guarantee
acceptable performance, and those copies will all share the same static
variables associated with the servlet’s class, you must manually synchronize
access to them to be thread-safe.

Request scope attributes:
thread-safe by default, the container handles each request with a single
worker thread, even when it’s forwarded or included, the RequestDispatcher
interface takes care of marshalling the Request object safely.  You have to
do strange things, like passing the request object out to an external
object, to be at risk here.

Session scope attributes:
not thread-safe.  The user can open multiple browser windows, which under
some configurations will all share the same cookies (thus the same
HttpSession object on the server).  Your page may also use frames, leading
to the same problem.  Or impatient users may hit the refresh button on your
page, again same problem.  Multiple accesses by simultaneous requests to the
same HttpSession object.

Context scope attributes:
not thread safe.  All servlets in the webapp share these, so they’re clearly
at risk of frequent multi-threaded access.

access to any sort of common resource (like an open socket, a file on the
hard disk, etc.):
not thread-safe.  Multiple requests coming in for any servlet that accesses
them can generate concurrent access.

Posted in 1 | 2 Comments »

Simple approach to relational database design

Posted by Vijay Kumar on February 14, 2007

First, create a list of important things (entities) and include those things you may not initially believe is important. Second, draw a line between any two entities that have any connection whatsoever; except that no two entities can connect without a ‘rule’; e.g.: families have children, employees work for a department. Therefore put the ‘connection’ in a diamond, the ‘entities’ in squares. Third, your picture should now have many squares (entities) connected to other entities through diamonds (a square enclosing an entity, with a line to a diamond describing the relationship, and then another line to the other entity). Fourth, put descriptors on each square and each diamond, such as customer — airline — trip. Fifth, give each diamond and square any attributes it may have (a person has a name, an invoice has a number), but some relationships have none (a parent just owns a child). Sixth, everything on your page that has attributes is now a table, whenever two entities have a relationship where the relationship has no attributes, there is merely a foreign key between the tables. Seventh, in general you want to make tables not repeat data. So, if a customer has a name and several addresses, you can see that for every address of a customer, there will be repeated the customer’s first name, last name, etc. So, record Name in one table, and put all his addresses in another. Eighth, each row (record) should be unique from every other one; Mr. Freedman suggests a ‘auto-increment number’ primary key, where a new, unique number is generated for each new inserted row. Ninth, a key is any way to uniquely identify a row in a table…first and last name together are good as a ‘composite’ key. That’s the technique.

Posted in Uncategorized | 1 Comment »

Java as a Popular Computing Platform

Posted by Vijay Kumar on October 30, 2006

Java is being widely used in building complex, distributed applications. The spectrum is amazing: on the one hand we have hand-held devices that run Java applications and on the other, we have huge servers running on-line transactions serving hundreds of users. Since its public debut a few years ago, Java technology has been growing steadily, and is now adopted by thousands of companies and organizations around the world.

Certain features of the Java language such as automatic garbage collection, multithreading, platform neutrality, absence of pointers, and robust exception handling facilitate the development of large-scale applications with amazing productivity. It is a widely prevalent notion that Java is much easier to learn and use compared to C++ and some even claim that Java has overtaken C++ as the world’s most popular object-oriented language. Although in some contexts Java’s performance might be unacceptable, the number and type of applications built on Java technology are continuing to grow day by day.

In this context it is wise to ask whether the quality of Java applications is automatically better than applications built using other technologies, for example, C++. It must be clearly borne in mind that Java by itself cannot guarantee a bug-free, high performance, reliable, scalable application. Features built into the Java language can only assist to some extent in achieving some of these quality factors. The bottom line is that Java programs can also be buggy and can suffer from performance-related problems. If the architecture, design and coding are not good, a Java program will not be very different from a bad program written in C++ or any other OO language.

Posted in Uncategorized | Leave a Comment »

Trojan horse

Posted by Vijay Kumar on September 26, 2006

For last two days I have been fighting with spyware in my system. To get rid of this spywares of my systems I went through diffrent sites and came to know about Trojan horse, an intrusive like application that watch your activity on your system and pass the information to other system.

A Trojan horse is a destructive program that masquerades as a benign application. Unlike viruses, Trojan horses do not replicate themselves but they can be just as destructive. One of the most insidious types of Trojan horse is a program that claims to rid your computer of viruses but instead introduces viruses onto your computer.

The term comes from the a Greek story of the Trojan War, in which the Greeks give a giant wooden horse to their foes, the Trojans, ostensibly as a peace offering. But after the Trojans drag the horse inside their city walls, Greek soldiers sneak out of the horse’s hollow belly and open the city gates, allowing their compatriots to pour in and capture Troy.

Posted in Uncategorized | Leave a Comment »

XML- basis for future web standards

Posted by Vijay Kumar on September 12, 2006

While wandering into a forum, I read following points. These provides a firm support to my thinking about the xml.

1. XML will certainly be the basis on which future Web standards are built.
2. XML will probably become the universal serial format for structured data.
3. XML will almost certainly become the basis for international publishing.
4. XML may replace all existing word processing and desktop publishing formats.

Posted in Uncategorized | Leave a Comment »

What is E-Commerce

Posted by Vijay Kumar on August 1, 2006

E-Commerce stands for Electronic Commerce, and is a general term used to describe all forms of trade on the Internet, especially those where payment is taken via the Web. In prctice e-commerce and e-business is used interchangeably. E-commerce is process of buying and selling of products and services over the Internet. basically this is transmit business information and transact business by using communication technologies. A very simple form of e-commerce is taking order over the phone.. e-Commerce or e-business refers to the business transactions between companies (B2B) or between companies and their customers (B2C).

Posted in Uncategorized | Leave a Comment »

Thanks to Open Source Revolution

Posted by Vijay Kumar on July 17, 2006

Hi All. First of all I would like to thanks to all people, communities, companies who have brought revolution in IT business by adopting Open source software. My special regards to all the developers who are donating their valuable effort in terms of code to enrich the open source movement. It is their effort only that I have been able to post my blog on internet.

Posted in Open Source Technology | 3 Comments »


Get every new post delivered to your Inbox.