a singleton is a class which is only created once (normally per process,
like a socket or connection manager, where you have an "expensive" resource
which you want to share among many threads of a process). the class is
normally written in such a way as to guarantee that only one instance can be
created. there are also singletons which can be one-per-machine, though
those are harder to implement by far, and typically require considerable
support from the operating system.
a process is basically a program and the space in which it runs - 1 program
instance, 1 process (normally).
a thread is a point of execution within a process. the simplest way to
explain threads is to consider the situation where you have an application
which reads user input and also reads and writes to a pair of sockets. in a
single-threaded application you would have to switch back and forth, first
checking if any user input was available and then, if not, checking for
socket data to be read/written, and then go back and check for user input
and so on and so forth. in a multi-threaded application you could have 1
thread just listen for user input and another thread listen for socket input
and yet another thread handle socket output. you still have a single
process, however the second solution makes your thread code simpler in that
each has a specific task.
multi-threading does add the need for synchornization, however, in those
places where the threads may "run into" each other - for instance the socket
output thread checks an internal send buffer and if anything is waiting
there to be sent it sends it. however you have to watch for the case where
1 thread is writing to that buffer when the other reads from it. this
requires sychronized methods to protect your threads from "stepping on each
other's toes" and causing sometimes very bizzare crashes/bugs.
the bottom line is typically multi-threaded applications run a little slower
on single-CPU systems because you need to do some setup and clean-up when
switching between threads (register and stack frame storage, for instance),
however mutli-threaded solutions can, if done right, break a complex task
very nicely into logical "jobs", each handled by a separate thread. think
of it as a single, many skilled worker versus many single-skilled workers
doing a job - the many-skilled worker is busy all the time and has to know
how to do everything (making them very complex), where-as the single-skilled
workers know how to do only one thing each, but working together (especially
in multi-CPU systems where threads can actually run simultaneously on
separate CPUs) can accomplish the same task just as fast, but since each
worker is that much simpler it makes the solution that much simpler (as long
as you handle the synchronization issues correctly, which is the real danger
in multi-threaded programming).
well, i'd say i babbled long enough. :) HTH!
......................ron.
-----Original Message-----
From: Nitin Gogia <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, December 28, 1999 8:44 PM
Subject: Out of the way....
>Can anyone tell me :-
>1. What is a singleton class ?
>2. Difference between Process and Thread ?
>
>Nitin
>
> -
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html