Mahadevan Gorti SS

+ Follow
since Jan 31, 2006
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mahadevan Gorti SS

When you applied -server flag for JVM, did you run the benchmark for some warmup time --so that JVM can findout hotspots properly and do necessary optimizations
17 years ago
Here another approach with RE. You have to test it thoroughly

Output for above program for input from f:/vob/test/data.txt is:
Usage: java [-DFILE=F:/vob/test/data.txt] REKindColorMatcher kind color

========= 1===========@0

========= 2===========@131

========= 3===========@355

========= 4===========@428
[ March 30, 2006: Message edited by: Mahadevan Gorti SS ]
18 years ago

Would you please give more details like(or check for your self) :
* What is the packet rate your are sending and receving
* What is the max/min/avg size of packets(UDP)?
* At what rate you started loosing packets
* What is system load
* What is Network interfaces capacity (in Mbytes/sec) for server/client machines
* What OS. Is server/client are in WAN type of setup
* Would it be possible to give breif snippet of your receiver's code.
* What is load of OS when you are running this programme
* What is the Logger you are using -- if load is causing problems
* What is the value for DatagramSocket: getReceiveBufferSize()
* What is the Thread priority for receiving the UDP packets
* Are the receiving packets recieved as fragmented(check via ethereal)

BTW, I was able to recieve UDP packets of sizes upto 1500(MTU of network interface) till 1500 packets/sec without loosing in java(that too 1.3.1) in java(with out use of JDK NIO) on PIII with 533 MHz and 256 MB RAM. I have not tried for packet-rates above 1500
As we have already covered all cases about Iterator/Enum/get cases, here are some additional points.

Here is a practical case where you would prefer a get from a Vector/AttayList over Iterator/Enumeration:
* Handling some tight loop of code where one has to process events more than 100/sec(for example). In each event loop, if one has to go thru the for-loop/Iterator(and the underlying data-structure is Vector/ArrayList/etc), for-loop is preferable for reason
-- It is faster than Iterator
-- It creates less garbage(so is the GC CPU utilization)
18 years ago
I think you should use JDK 1.4 regular expression(RE) for doing that sort of search. Sun has NIO examples at

OR you can use RE for you code like:
18 years ago
For a cases where you know the conditions is met -- some boolean condition made true/false some where else in program (with a different thread of execution), you can follow Stan's method of breaking out of loop. I think your case is mostly of CPU consuming task(with no blocking calls in code).

But there are cases, where you are blocked in JVM in following cases:
* Thread.sleep(x)
* Object.wait()
* Some OS specific blocking calls like IO, network sockets,etc.

In these cases, even if one detect a boolean condition, one cannot come out of the loop -- as calling thread is blocked.

One way out for such conditons is:
* Put the code for the long-time-consuming job in method
* Give this job to a Thread-Pool with a timeout parameter. Note down the Thread which is doing the job
* If thread pool does not support timeout of a task, write your timeout handler something like:
* Run a separate Timer task to monitor time for each long-task that has been submitted and after timeout
* Interrupt the blocked thread with proper checks

Hope this helps
18 years ago
First for getting OS,OS-Version, Architecyure, JVM version, JVM vendor, use System.getProperties().

For getting physical memory info and processor extra details use OS specific
program and run that program via (Runtime.exec) and parse and get the required lines. Here are some commands that would be of use to you.

For windows NT(Also see 'typeperf' command, specified elsewhere in this forum)

For general Unix stuff

For solaris(for getting processort info, phy. memory,etc).

For Linux for getting Physical/swap memory)
18 years ago
Hope this link will take care of all possible future cases & conbinations
18 years ago
You can try Regular expression (if your JDK > 1.4) like:

[ March 26, 2006: Message edited by: Mahadevan Gorti SS ]
[ March 27, 2006: Message edited by: Mahadevan Gorti SS ]
18 years ago
Try running ethereal(network packet captuerer from ) on both server and client and try to start transaction and see for packets traversed between server/client
Apart from 'typeperf' -- which is not available in other Windows versions(one has to download from web with possible non-working version of typeperf.exe in another windows version), one can use 'pslist.exe' from pslist.exe is available in

pslist will also be useful for one to see which thread is taking more time(OR doing tight loops in a JVM).

If you JDK 1.5 onwards, pure java code without resorting to Runtime.exec ( which is costly) using JMX package The JMX-bean/classes you are interested are:
* ThreadInfo
* ThreadMBean
[ March 24, 2006: Message edited by: Mahadevan Gorti SS ]
18 years ago

Originally posted by Ernest Friedman-Hill:
You're describing a sort of degenerate "Abstract Factory" pattern; usually the factory class (the one with the "create" method) is a separate class from the product class (the one that is created.) See here for more of a description.

As I said earlier, you can use clone if you can.

Definetely I used "Abstract Factory" pattern, but it is not a degenrate case . Even in ""Abstract Factory" pattern case, how one can generate classes in runtime with these conditions these may depends on restrictions on practical situation that arised in my case)
  • One cannot use Reflection -- for performace reasons
  • One cannot implement Cloneable interface in the class heirarchy( the said base/some-sub classes cannot implement Cloneable interface)
  • Similiar code/pattern should be used in corresponding C/C++ code(that complements java code)
  • Use of switch case in "Abstract Factory" implementation is prohibited -- for obvious reasons of long term maintainance issues
  • Use of if-else-statements in "Abstract Factory" implementation is prohibited -- for obvious reasons of long term maintainance issues

  • So tell me if you have any other method/way/suggestion to do same thing in "Abstract Factory" with above conditions.
    18 years ago
    As rightly said above, unless you have some important/compelling reason to avoid synchronization-lock, there is no need for one to see for other altrenatives.

    If you want multiple threads to access a shared resource without sync-lock, you can see Doug Lea's Concurrent HashMap(now in JDK 1.5). You can use similair strategy for your code.

    If Still you wanted to go ahead, you can see JDK 1.5 package ' java.util.concurrent.atomic' -- for AtomBoolean, AtomicIntger, AtomicLong for customization for your code(these can be used my mutiple threads to have detectionb mechanism for entring/doing something in a method). But beaware, the methods in those atomic-xlasses might involve tight spinloop(if the other thread takes much time to complete). Also these classes do have native methods -- ofcourse written by Sun , in platform independent way.
    Apart from normal use of clone as specified Sun and Others, one can use clone innovatively for creating classes in runtime without reflection,etc.

    This can be really useful for a case of Classes(various strategies) -- which are derived from a common base class, to be executed for different conditions(strategies)

    As sun's clone is too-many if's-but's(for good cause/safety), I have implemented my-own close with an hierarchy of classes which do use creative use of clone. I named my method to create(instead of clone and to stop its unwanted checks/restrictions in my code). I not here saying clone can't be used in my case -- what I am suggesting is another way using clone in practical applications.

    So concept is like this:
  • Have a parent class have an abstract methods in Base-class with create method and some doJob/run,preJob/postJob methods for doing real work
  • Let is child class implement the create method which will do a new of that child class . Also child class implements some get/set methods and doJob/run for doinf real-work.
  • When JVM has started , register of all child classes in static Map with public methods to get an instance of that class(with a key of string/integer/some-key) . This could be also from a property file with class-names versus some string/integer/some-key
  • In a class where we need to create different child class for different strategy, get the instance of child-class by passing appropriate key.
  • Now create appropriate child class by calling create method. Do any pre processing in that child class instance by using preJob. Then call doJob/doJob/run. After the that call postJob.

  • By use in this way one can add more strategies or handlers(without using Reflection/switch case statements).

    Same methodolgy can applied on other languages -- C,C++,etc
    18 years ago
    Here some steps to tacke the issue of high Cyclomatic Complexity Number(CCN):

    * Generalize the code/methods
    * Read Martin Fowlers' Refactoring book -- this contains lots of ideas
    * Most of the developers has an idea/concept that adding more methods will reduce the performance and write big methods with lots of if/else, indentation,etc --which finally leads to high CCN. But performance wise, most of the performant code is concetrated only in 20% of whole code base(80-20 rule).So one has to see, is this method(that is having high CCN) is really performance critical code-path. If not,then break that method to small methods to generalize.

    * Introduce the checks in organization's build process to STOP inserting the code with high CCN in to production loads( this process may have some exception cases for old code and new code based on need/etc. But these exceptions need to be ratified by discussion).
    * Use Checkstyle in ANT build files to give feedback/warning on CCN numbers
    * Use Checkstyle in ANT build files to give feedback/warning on large method NCSL(non commented source lines)
    * Use Checkstyle in ANT build files to give feedback/warning on deep indentation in code base
    * Educate the Developers about CCN. Let them know/use JavaNCSS package for getting the CCN numbers
    * Educate the Developers about OOP(for new/old/extension design/coding) for reusability am=nd maintainable code
    * Educate the Developers about the Refactoring(Martin Fowlers book read is a MUST). Also let them use Eclipse/other-famous-IDE's refactoring tools for reducing the CCN/etc
    18 years ago