Sampath's Blog
Monday, August 12, 2019
  Multi threaded worker sample
Multi threaded worker sample

A Simple program to achieve multi task using multi thread in java

package myProject;

import java.util.ArrayList;
import java.util.List;

public class SampleThreadProcessor {
static List lst = new ArrayList<>();

public static void main(String[] args) throws InterruptedException {
ThreadGroup tg = new ThreadGroup("Group A");

for (int i = 0; i < 115; i++) {
lst.add(i);
}

System.out.println(lst);

int startCount = 0;
int endCount = 0;
int recPerBatch = 15;

int maxThreadCount = Runtime.getRuntime().availableProcessors() * 2;

System.out.println("###### maxThreadCount "+maxThreadCount);

System.out.println(lst.size() / recPerBatch);

System.out.println(tg.activeCount());
while (true) {
if (tg.activeCount() <= maxThreadCount) {
System.out.println("Thread count = " + tg.activeCount());

endCount = startCount + recPerBatch;
if (endCount > lst.size()) {
endCount = lst.size();
}

if (startCount < lst.size()) {
System.out.println("Starting theard from " + startCount + " to " + endCount);
Thread t = new Thread1(tg, lst.subList(startCount, endCount), tg.activeCount()+1);
Thread.sleep(1000);
t.start();
startCount = endCount;
} else {
break;
}
System.out.println("#########" + startCount);
} else if (tg.activeCount() == 0) {
break;
}
}
System.out.println(tg.activeCount());

System.out.println("done");

}

}

class Thread1 extends Thread {
List lst = null;

Thread1(ThreadGroup tg, List sst, int thCnt) {
super(tg, "");
lst = sst;
this.setName("Thread "+thCnt);
}

public void run() {
System.out.println("Thread started" + lst);
try {
Thread.sleep(15000);
System.out.println(this.getName());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

 
Tuesday, March 24, 2009
  Difference between Scrum, XP
1. Scrum iterations are 2-4 week long, XP- 1-2 weeks long
2. Scrum do not allow changes into their sprints, XP Allows
3. Scrum tasks prioritised by team, XP- by customer and stricter
4. Scrum does not follow engring practices unlike XP follows TDD, pair programming, simple design, refactoring, and so on
 
 
 
Thursday, May 22, 2008
  Great Indian Developer Summit
It is really a great summit. i think 120 presentations.. spread for 5 days.. amazing summit sponsored by some great companies like Oracle, msdn , Nokia, SAP, Amazon, Adobe etc.. I could see the over helming response to the summit.

I will post more on the sessions i attended in detail later as still i am creating writeup on the same.

There are a lot of stalls open to know more about recent developments in the IT and many offers are on the way.

simply great.
 
Thursday, March 02, 2006
  Called from
package myProject;

public class CalledFrom {
public static String getCaller() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
int i = Math.min(3, stackTrace.length - 1);
return stackTrace[i].getClassName() + "." + stackTrace[i].getMethodName() + "()";
}

public static void printCaller() {
System.out.println(getCaller());
}

public static void main(String[] args) {
CalledFrom.printCaller();
}
}

 
Tuesday, January 24, 2006
  Log4j - Real performer
I tried to find out the different scenarios with/out log4j... Really great output

consider the following code snippet,

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;

public class MyApp {

static Logger logger = Logger.getLogger(MyApp.class);

public static void main(String[] args) {
long start = System.currentTimeMillis();
// BasicConfigurator.configure();

//logger.setLevel(Level.DEBUG);
for (int i = 0; i <>
// logger.info("Entering application.");
// logger.info("Exiting application.");

System.out.println("Entering application.");
System.out.println("Exiting application.");
}

long end = System.currentTimeMillis();
System.out.println(end - start);

}
}


with this.. program ends in around 6500 milli secs
disable SOP and enable log and run in ERROR level - ends in around 40 milli secs
disable SOP and enable log and run in DEBUG level - ends in around 13000 milli secs

 
Thursday, December 15, 2005
  About Junit Test

A test suite may contain any class that implements the Test interface, including other suites.

Test Case. A test case, such as AmountTest, collects a set of one or more related test methods and is usually a subclass of the framework class TestCase. Each test method name must start with “test” and has no arguments, e.g., testSetCurrency().
Test Suite. A test suite is a collection of tests that are run at the same time. A test suite is often constructed dynamically from selected test cases or may contain only a single test method.
Test Runner. A test runner is a utility used to run a suite of tests. The runner may provide a graphical presentation, such as an Eclipse view, or a command-line execution that is incorporated into automated build files.

Code that creates the objects used by the tests. This testing context is
referred to as a test’s fixture. The setUp() and tearDown() methods are
part of the fixture.
 

ARCHIVES
December 2005 / January 2006 / March 2006 / May 2008 / March 2009 / August 2019 /


Powered by Blogger