Execute all methods in a callass (use reflection?)

Hi there,
I�m trying to create a method that calls all methods in the class (except itself and the constructors). All methods returns an element and this element should be added to a linked list.
I wonder if there is such possibility to do that (I know that JUnit suite does something similar where you don�t have to specify all tests and it is generated for you)
I tried something with reflection (like the code below) but that obviously it didn�t work out.
Any idea?
     public LinkedList getElements()
          Method m[] = MyClass.class.getDeclaredMethods();
          for (int i = 0; i < m.length; i++)
               elementList.add(m.toString());
          return this.elementList;

all methods returns an Element. I want to avoid typing somthing like:
public LinkedList()
linkedList.add(getConstantValue());
linkedList.add(getPetroName());
linkedList.add(getFileReferenceNumber());
// instead I wish to have somthign like:
//for loop on all methods
// linkedList(exec method 1..2..3..4.)
     public Element getConstantValue()
          return new Element ("ffsd", "CONS", 3,42, line);
     public Element getPetroName()
          return new Element ("ffzx", "PXNM", 49,45, line);
     public Element getFileReferenceNumber()
          return new Element ("aawr", "CSTF", 27,94, line);
     public Element getIdentification()
          return new Element ("ttre", "CLID", 8,121, line);
     }

Similar Messages

  • Using Reflection - Method.invoke()

    Hi all,
    Facing a problem in using the Reflection API. Can anyone tell me how to use the invoke, which is available with Method. Problem statement. - I want to create a method. And then invoke that method using method1. invoke. But this can take only the following arguments - (Object, Object [ ] ). I cant figure out why I need to pass on an object ? and an array of objects ?

    If you read the docs for Method.invoke, you'll see that the first argument is the object on which you wish to invoke the method, and the second argument is the parameters (with primitives wrapped appropriately).
    foo.bar("abc", 123);
    // becomes
    meth.invoke(foo, new Object[] {"abc", new Integer(123) }); (if I haven't screwed up the syntax of the array initialization)
    http://java.sun.com/docs/books/tutorial/reflect/

  • Method to execute all jobs at a time

    Hi Experts,
    I have 100 jobs i want to execute all at a time,
    Any idea or suggestion,
    If we can do throught script ,Sample Script please
    Thanks
    Madhu

    Hi Madhu,
    You can execute all jobs using different method like through "Data Services management Console scheduling option" or through script (SHELL/BATCH).
    But here again you have to check the below points before executing all jobs
    Check the current server configuration because if you schedule all 100 job in one time it will put more load on server
    If you have dependency in jobs please run that jobs/schedule that jobs first.
    Please refer the below link for how to execute for LINUX or Windows
    Steps for executing BODS job from Unix Script with user defined global parameters
    http://scn.sap.com/community/data-services/blog/2013/09/02/steps-for-executing-bods-job-from-unix-script-with-user-defined-global-parameters
    SAP Data Services - Running & Scheduling Data Services Jobs from Linux Command Line using Third party Scheduler
    http://scn.sap.com/community/data-services/blog/2012/08/22/sap-bods--running-scheduling-bods-jobs-from-linux-command-line-using-third-party-scheduler
    http://www.dwbiconcepts.com/etl/23-etl-bods/39-one-stop-to-sap-bodibods.html?showall=1
    Thanks,
    Daya

  • How to create a line without using execute action method.

    Hi All,
    I want to create a line whose weight and co-ordinate are given to me. I am using ActionDescriptor and execute action method to do this.
    Here is my code:
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        var idStrt = charIDToTypeID( "Strt" );
        var idHrzn = charIDToTypeID( "Hrzn" );
        var idPxl = charIDToTypeID( "#Pxl" );
        var idVrtc = charIDToTypeID( "Vrtc" );
        var idPnt = charIDToTypeID( "Pnt " );
        var actRef = new ActionReference();
        actRef.putClass( idcontentLayer );
        var layerDesc = new ActionDescriptor();
        layerDesc.putReference( charIDToTypeID( "null" ), actRef );
        var lineDesc = new ActionDescriptor();
        lineDesc.putClass( charIDToTypeID( "Type" ), stringIDToTypeID( "solidColorLayer" ) );
        var propertyDesc = new ActionDescriptor();
        var strtPointDesc = new ActionDescriptor();
        strtPointDesc.putUnitDouble( idHrzn, idPxl,  startX);                         //startX, startY, endX, endY are given..
        strtPointDesc.putUnitDouble( idVrtc, idPxl, startY);
        var endPointDesc = new ActionDescriptor();
        endPointDesc.putUnitDouble( idHrzn, idPxl, endX );
        endPointDesc.putUnitDouble( idVrtc, idPxl, endY );
        propertyDesc.putObject(  charIDToTypeID( "Strt" ), idPnt, strtPointDesc );
        propertyDesc.putObject( charIDToTypeID( "End " ), idPnt, endPointDesc);
        propertyDesc.putUnitDouble( charIDToTypeID( "Wdth" ), idPxl, weight );               // weight is given.
        lineDesc.putObject( charIDToTypeID( "Shp " ), charIDToTypeID( "Ln  " ), propertyDesc );
        layerDesc.putObject( charIDToTypeID( "Usng" ), idcontentLayer, lineDesc );
        executeAction( charIDToTypeID( "Mk  " ), layerDesc, DialogModes.NO );
    Is there any other way to do the above (using photoshop scripting method)?
    Thanks,
    AI

    You can only create normal and text layers using the Object Model. For other layer types you have to use Action Manager.

  • How can i get all java class names from a package using reflection?

    hi,
    can i get all classes name from a package using reflection or any other way?
    If possible plz give the code with example.

    You can't, because the package doesn't have to be on the local machine. It could be ANYWHERE.
    For example, via a URLClassLoader (ie from the internet) I could load a class called:
    com.paperstack.NobodyExpectsTheSpanishInquisitionI haven't written it yet. But I might tomorrow. How are you going to determine if that class is in the package?
    This subject comes up a lot. If you want to do something a bit like what you're asking for (but not quite) there are plenty of threads on the subject. Use google and/or the forum search facility to find them.
    But the answer to your question, as you asked it, is "you can't do that".

  • Calling a pkg from managed code and then using reflection to call a method from a script task

    Hi we run 2012 std.  I have some pretty good evidence that when I call my pkg from a .net service, a script component in that pkg fails when trying 2 use reflection to load and invoke our .net message history method.  The exception is either on
    the invoke or in the message history method.  I suspect its in the method but will take additional steps 2 verify.
    But when I run the pkg stand alone, it has no problem and the method does what it is supposed 2 do.
    There r no vars passed from the service to the pkg.  I wonder if its a managed to unmanaged to managed issue that the community is already aware of.  If not, my apologies 4 posting this quickly.
    I'll post more info here as I collect it. 

    we have 2 theories after showing the exception trace to folks who r more adept at managed code.
    the first is related to the fact that our 3rd party dlls (I think entity framework is included in these) r older versions.  I don't want to discount this theory but we have some evidence already that this might not be true.
    I hope I can do justice to the 2nd theory but will make it clearer and clearer as I get a better understanding.  I believe this is what Arthur was saying and I applaud his instincts.  They explained that .net is so "smart" that it detected
    a change in namespace  (ie context as Arthur said) and purposely threw an exception 2 save us from ourselves.  The workarounds discussed were a bit over my head but I will continue trying to better understand it.  The fact that many of the methods
    we call after reflection r now merged into one assembly seemed relevant to the discussion and possible workarounds.   
    this link came up in their discussion and I believe the bottom line here is that by qualifying assembly names further (in config?)r, a workaround is possible. 
    http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx  .
    This link came up as well and has something to do with ILMerge and workarounds to ILMerge. 
    http://elegantcode.com/2011/04/02/dynamically-load-embedded-assemblies-because-ilmerge-appeared-to-be-out/  .
    Finally, this link came up and seems to have something to do with embedding your dlls in one assembly without them losing their identity.
    http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
    I'll post more here as we muddle thru this.

  • How to access private method of an inner class using reflection.

    Can somebody tell me that how can i access private method of an inner class using reflection.
    There is a scenario like
    class A
    class B
    private fun() {
    now i want to use method fun() of an inner class inside third class i.e "class c".
    Can i use reflection in someway to access this private method fun() in class c.

    I suppose for unit tests, there could be cases when you need to access private methods that you don't want your real code to access.
    Reflection with inner classes can be tricky. I tried getting the constructor, but it kept failing until I saw that even though the default constructor is a no-arg, for inner classes that aren't static, apparently the constructor for the inner class itself takes an instance of the outer class as a param.
    So here's what it looks like:
            //list of inner classes, if any
            Class[] classlist = A.class.getDeclaredClasses();
            A outer = new A();
            try {
                for (int i =0; i < classlist.length; i++){
                    if (! classlist.getSimpleName().equals("B")){
    //skip other classes
    continue;
    //this is what I mention above.
    Constructor constr = classlist[i].getDeclaredConstructor(A.class);
    constr.setAccessible(true);
    Object inner = constr.newInstance(outer);
    Method meth = classlist[i].getDeclaredMethod("testMethod");
    meth.setAccessible(true);
    //the actual method call
    meth.invoke(inner);
    } catch (Exception e) {
    throw new RuntimeException(e);
    Good luck, and if you find yourself relying on this too much, it might mean a code redesign.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Invoking a method using reflection with json data as argument

    Hi,
    I want to invoke a method using reflection and this method have one argument . Now I want to pass a json data as an argument to this method .Please see the following code.
    int HelloWorld(int Id){
    return Id;
    json data{"Id":43}
    how can I use the reflection to use the json.
    Please provide your guidelines

    Thanks for your reply, I am building a windows console application .And I want to convert the json data to object array to use in Method Base.Invoke method.
    Regards,
    Ethan
    Maybe you could select the correct language development forum here:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages&filter=alltypes&sort=lastpostdesc
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • The iTune cannot detect my iPhone. I have already tried all methods suggested, including re-installling iTune, re-activating Apple Mobile Device, plugging in various USB ports, and etc. I use windows 7. How can I solve this?

    The iTune cannot detect my iPhone 4S. I have already tried all methods suggested, including re-installling iTune, re-activating Apple Mobile Device, plugging in various USB ports, and etc. I use windows 7. How can I solve this?

    The new cable is completely new, and my computer can detect the phone as a drive, and battery charging is ok. So I believe the USB cable works properly. It is so weird that just iTune itself cannot detect the phone, and it is of the most updated version. What else can I do? Thanks.

  • Using reflection to get method body

    Hi,
    I'm just getting into this side of program and while I understand the use of reflection in oredr to obtain the constructor and method, parameters, fields etc I was wondering if its possible to grab the method body and copy it into a string.
    So for example in the following class...
    class MyClass
    private String str;
    MyClass(){}
    public String MyMethod(String s)
    str=s;
    str=str+" was the String";
    System.out.println(str);
    return str;
    ...I need to capture just this code..
    str=s;
    str=str+" was the String";
    System.out.println(str);
    return str;
    ...as a string
    The reason i need to do this is that I'm programming a mechanism for storing objects and their methods using JDBC.. I could use object serialisation and store as a blob, but I'm wanting to store the attributes of a class as seperate parts so I can retrieve bits of code from the database at some later time.
    Thanks for any help you might give me
    peace
    neil

    You say that you are trying to store the method body
    into a database. This is to allow you to store an
    object and its methods into a database. Are you trying
    store the method text or its implementation (i.e class
    or java). If it is the implementation then just
    serialize the found method object using reflection.
    WHY are you doing this ?? what about private methods,
    class variables, class methods ???Hi, yes it is confusing to explain, but I'm experimenting with a new programming paradigm called AspectJ and I've only just got into Reflection. I'm creating a repository of Aspects (same as classes but with added functionality and some limitations) with JDBC and don't want to just serialise the object as a blob and so have created data tables to hold different parts of the anatomy of an Aspect and this was the only thing I was getting stuck on.
    The idea is that the user is able to recall these whole aspects (or a part of them such as a method) on the fly and use them in a program. I realise that ther will be problems because these methods may have other dependencies such as the ones you explain above but its just experimental at the moment and those are the kinds of things I'm wanting to find out more.
    I've seen examples of reflection for Objects but never for methods. So it is possible to capture just a method by serialisation using reflection? Any examples would be much appreciated.
    Peace
    Neil

  • Difference between invoking a method using reflect.proxy and reflect.Method

    Could any one tell me the difference between invoking a method using reflection java.lang.reflect.Method and java.lang.reflect.Proxy
    using both the class, we can invoke a method at runtime
    1)
    Method mthd=cl.getMethod("methodName",parameterName);
    Integer output=(Integer)mthd.invoke(new RunMthdRef(),input);
    2)
    Proxy.newProxyInstance(super.getClass().getClassLoader(), new Class[] { adapter }, new SomeClass(this));
    Does anybody have any idea?

    The two idioms are fundamentally different. Using java.lang.reflect.Method is how we call a method on a class, using Proxy is how we intercept that method call. An exercise for you, to illustrate that they do not do the same thing: write a simple class with one method, then use java.lang.reflect.Method to invoke that method, and then use a Proxy to invoke that method

  • ParameterNotBound exception when using reflection to set params

    I'm using the JDBC type 4 thin driver going to 8.1.6 on Win2K.
    I have an EJB method that uses reflection to do the set<type> methods on the PreparedStatement to set the positional parameters for a SQL query statement.
    The first time the method executes, I get a ParameterNotBound exception. I've used the debugger to determine that all the parameters are bound - at least the set<type> methods have been called.
    The wierd thing is that all subsequent calls to the the SQL query method work fine.
    Does anyone here know where in the PreparedStatement class are the parameters bound. What data element? I'm trying use the debugger to determine what's different the first time the method is called.
    Thanks,
    Rich Bolen

    Congrats Darek!
    That function really works... here is my program test:
    package integracao.sap.teste;
    import java.util.Properties;
    import integracao.sap.config.ConfigUtil;
    import integracao.sap.funcao.RFC_READ_TABLE;
    import com.sap.mw.jco.IRepository;
    import com.sap.mw.jco.JCO;
    public class TestJCOError {
         private static Properties config;
         private static JCO.Client createJCOClient(){
              JCO.Client client = JCO.createClient(config.getProperty("numClient"), config.getProperty("user"), config.getProperty("password"), "EN", config.getProperty("host"), config.getProperty("numPrograma"));
              return (client);
    @param args
         public static void main(String[] args) {
              config = ConfigUtil.getConfig();
              JCO.Client client = createJCOClient();
              client.connect();
              IRepository repository = JCO.createRepository("REP", client);
              JCO.Function func = RFC_READ_TABLE.createFunction(repository);
              func.getImportParameterList().setValue("MARC", "QUERY_TABLE");
              func.getImportParameterList().setValue(";",    "DELIMITER");
              func.getTableParameterList().getTable("OPTIONS").appendRow();
              func.getTableParameterList().getTable("OPTIONS").setValue("MATNR = '000000000000000011'", "TEXT");
              func.getTableParameterList().getTable("FIELDS").appendRow();
              func.getTableParameterList().getTable("FIELDS").setValue("MATNR", "FIELDNAME");
              client.execute(func);
              JCO.Table table = func.getTableParameterList().getTable("DATA");
              System.out.println("NumRows: " + table.getNumRows());
              System.out.println("Content: " + table.getValue("WA"));
    Result:
    NumRows: 1
    Content: 000000000000000011
    Hope it helps everybody!
    Regards,
    Danilo Andrade

  • Problem to calling readObject(java.io.ObjectInputStream) using reflection

    Hi,
    I am facing the following problem
    I have an Employee class its overridden the following below methods
    private void readObject(java.io.ObjectInputStream inStream) {
         inStream.defaultReadObject();
    I am trying to call this method using reflection.
    my code is like this
         Class fis= Class.forName("java.io.FileInputStream");
         Constructor fcons = fis.getConstructor(new Class[]{String.class});
         Object fisObj = fcons.newInstance(new Object[]{"C:\\NewEmployee.ser"});
         Class ois= Class.forName("java.io.ObjectInputStream");     
         Constructor ocons = ois.getDeclaredConstructor(new Class[]{InputStream.class});
         Object oisObj = ocons.newInstance(new Object[] {fisObj});
         Method readObj = aClass.getDeclaredMethod("readObject", new Class[]{ois});
         readObj.setAccessible(true);
         Object mapObj = readObj.invoke(employeeObj,new Object[]{oisObj});
    The above code is call the readObject method, but it is failing while executing inStream.defaultReadObject() statement
    I am getting the following exception
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at HackEmployee.reflect(HackEmployee.java:49)
    at HackEmployee.main(HackEmployee.java:131)
    Caused by: java.io.NotActiveException: not in call to readObject
    at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:474)
    at Employee.readObject(Employee.java:77)
    ... 6 more
    can anybody help me?
    ~ murali

    Hi,
    Here is the simple example.
    public class Employee implements Serializable {
    static final long serialVersionUID = 1L;
    static final int _VERSION = 2;
    private int eno;
    private String empName;
         private String paaword;
         private void readObject(java.io.ObjectInputStream inStream)
    throws IOException, ClassNotFoundException {
         int version = 0;
         BufferedInputStream bis = new BufferedInputStream(inStream);
         bis.mark(256);
         DataInputStream dis = new DataInputStream(bis);
         try {
              version = dis.readInt();
              Debug.println(Debug.INFO, _TAG, "Loading version=" + version);
         } catch(Exception e) {
              dis.reset();
         switch(version) {
              case 0:
              case 1:
                   inStream.defaultReadObject();
                   migrateDefaultEmployeeToEncryptionPassword();
                   break;
              case _VERSION:
                   inStream.defaultReadObject();
                   break;
              default:
                   throw new IOException("Unknown Version :" + version);
         private void writeObject(ObjectOutputStream aOutputStream)
    throws IOException {
         aOutputStream.writeInt(_VERSION);
         aOutputStream.defaultWriteObject();
    Now I am writing a tool that need to read data and print all the field and values in a file.
    So I am trying the same with reflecton by calling readObject(ObjectInputStream inStream).
    But here I am facing the problem, it is geving java.lang.reflect.InvocationTargetException while calling migrateDefaultEmployeeToEncryptionPassword(.
    Hope you got my exact scenerio.
    Thanks for your replay
    ~ Murali

  • Implementing Simulator Using Reflection

    hey my friends,
    I'm working on implementing a Simulator for PIC Microcontroller which executes Assembly instructions and makes appropriate changes in Register File and Memory.
    The way I execute instructions is as follows:
    I have an abstract parent class called Instruction, then I made each individual instruction as separate class that extends Instruction parent class. Now I use reflection to execute each individual instruction by creating a new object of that instruction passing its parameters and then calling execute() method.
    Example :
    MOVE W, 0xFF
    CLRF PORTA
    my Java code will look like :
    Class instructionClass = Class.forName("MOVE");
    Instruction inst = (Instruction) instructionClass.newInstance();
    inst.passParameters(String[] parms);
    inst.execute();
    instructionClass = Class.forName("CLRF");
    inst = (Instruction) instructionClass.forName("PORTA");
    inst.passParameters(String[] parms);
    inst.execute();
    Is there a better fast idea or I shall keep on the same way ?
    Message was edited by:
    HypnotiC
    Message was edited by:
    HypnotiC

    If you know all the types of instruction you could write a method that returns
    an object based on the first word of the line.public abstract class AbstractInstruction {
        protected String[] paramArr;
        protected void setParam(String[] line) {
            paramArr = new String[line.length - 1];
            System.arraycopy(line, 1, paramArr, 0, line.length - 1);
        public abstract void execute();
        public AbstractInstruction create(String[] line) {
            AbstractInstruction ret;
            if(line[0].equals("MOVE")) ret = new MoveInstruction();
            // else if() etc
            else ret = new ClrfInstruction();
            ret.setParam(line);
            return ret;
    class MoveInstruction extends AbstractInstruction {
        public void execute() {
            // do something with paramArr
    class ClrfInstruction extends AbstractInstruction {
        public void execute() {
            // do something else with paramArr
    }

  • Generic worker threads using reflection?

    Many of my classes have methods that take a long time to finish. I am doing ok, but am unhappy with the design. I want a clean divide between the time consuming algorithm methods and threading. So this is what I came up with:
    public class Main {
      public static void main(String[] args) {
        Class[] cArgs = new Class[1];
        cArgs[0] = (new double[1]).getClass();
        Method m = Algorithms.class.getMethod("transform", cArgs);
        Object[] objArgs = new Object[1];
        objArgs[0] = data;
        Worker w = new Worker(m, null, objArgs);
        w.start();
        // do some other work.
        // sometimes check-in and test if the worker has finished.
        // might need to use "synchronized(w) {}" and "w.wait()"
        double[] result = (double[]) w.getResult();
    public class Algorithms {
      static double[] transform(double[] vector) {
        // do work....
        return results;
      // more static methods...
    public class Worker extends Thread {
      Method m;
      Object obj;
      Object[] args;
      Object returnValue;
      boolean started = false;
      boolean finished = false;
      Worker(Method m, Object obj, Object[] args) {
        this.m = m; this.obj = obj; this.args = args;
      public void run() {
        synchronized (this) {
          started = true;
          returnValue = m.invoke(obj, args);
          finished = true;
      public Object getResult() { return returnValue; }
      public boolean isStarted() { return started; }
      public boolean isFinished() { return finished; }
    }I don't quite yet understand the complete mechanics of thread sync, but in the simple testing so far the parallelism has worked as expected.
    To me, that conceptually looks like a clean split between the algorithms and the parallelism. However, implementation-wise that looks pretty sketchy. Reflection alone should almost never be used. Threading correctly is very difficult. Combining the two just seems like a really bad idea, yet I really like the design and can't think of any good alternatives that adhere to best practices oop concepts. Any advice would be welcomed.

    rerf wrote:
    Peter__Lawrey wrote:
    rerf wrote:
    My only observation was that static methods and interfaces conceptually have no connection. Thus, static methods are not allowed in interfaces. Development is about bring together elements from different concepts. You sound like you are trying to keep your code "pure", but provide no justication for doing so.Only justification is self-study. I had been programming along quickly, and then it got so messy I wanted to stop and redo everything using best-practices oop concepts as I understand them.In that case I would point out that static methods don't follow the OOP model. Perhaps you could drop the static methods.
    So, when I write a static method I should never think about interfaces. static methods can have interfaces as parameter types, and can call methods on interfaces, and interface method implementations can call static methods. Again your need to keep these seperate makes no sense to me.What I mean is that I do not want the class to which the cpu intense algorithm belongs to have to implement Runnable or Callable.Then I suggest you call the "class to which the cpu intense algorithm" from another/anonymous class which implements Runnable ro Callable.
    My unit of work is not an entire object (rather its one static method). So, how can I get a thread to execute that? A non-static method can call a static method. Is there really a need to make things any more complicated than that?I did not know. I am trying to find a coding style.
    While re-writing my code, and trying to be oop, I realized all I needed was the method, its parameters, the return value, and a thread to execute it. But when I got into the reflection, I decided its probably a bad idea, but still decided to ask for a second opinion. as well as a possible alternative.An anonymous class like Runnable to wrap the method and its arguments. I suggest Runnable instead of Callable, because you have to do something with the result which the Runnable can do in the same thread. The Callable passes the result back to the calling thead to process which is usually more complicated and less efficient.
    I am still not sure of the best way to deal with executing static methods in parallel. Here is the signature of a method I will run tonight in batch.
    static void patternMatch(Reader in, Writer out, Connection conn) throws Exception;
    I want to invoke that method 10-times and have the data processing happen in parallel.
    public static void main(String... args) {
    Executor exectors = Executors.newFixedThreadPool(N_THREADS);
    for(int i=0;i<10;i++) {
      final Reader in = ....
      final Writer out = ....
      final Connection conn = ...
      executor.executor(new Runnable() {
        public void run() {
            try {
                patternMatch(in, out, conn);
            } catch (Throwable t) { // I suggest you catch Throwable even if there are no checked exceptions or they can be discarded.
                // handle t
    executor.shutdown(); // shutdown when finished.
    // no need to wait as there is nothing to do when finished.
    When all the threads finish, the main method can exit.Why? What would happen if the main method exited when there was nothing left for it to do?

Maybe you are looking for

  • ITunes Freezes when I try to sync my new iPod Touch

    I can't sync my new iPod with my iTunes library. I have posted in the iTunes forum, although my title says that I have solved the issue. It isn't, so I'm contemptlating reposting. I bought a 64gig iPod Touch the other day to replace an old broken iPo

  • My New Ipod will not show up in Itunes? I have tried everything!

    I had to get a new ipod because my old one's home button got stuck so they replaced it and now when I try to connect it to my computer it will charge and show up in my computer but not on itunes. I have tried a different usb port, reinstall itunes, r

  • Date criteria in Crystal Reports

    SELECT A.EMPLID, C.NAME, A.SHEET_ID, A.SHEET_NAME, TO_CHAR(A.ACCOUNTING_DT,'YYYY-MM-DD'), A.POST_STATUS_EX, A.BUSINESS_UNIT_GL, TO_CHAR(B.TRANS_DT,'YYYY-MM-DD'), B.EXPENSE_TYPE, B.MERCHANT, B.DESCR254, B.TXN_AMOUNT FROM PS_EX_SHEET_HDR A, PS_EX_SHEET

  • Dynamic Combination of structure in Query

    I have a characteristic structure cross with a key figure structure characteristic structure C1 - A C1 - B C1 - C key figure structure KF1 KF2 KF3 Report layout             A                     B                    C xxx      KF1 KF2 KF3    KF1 KF2

  • LSMW using IDOC - Loading Communication infotype 0105(HR Master)

    Hi, Loading IT0105(email data) using LSMW IDOC. Input File: YPERNR,YCHOIC,YSUBTY,YBEGDA,YENDDA,ID_NUMBER 08999989,0105,0010,20040101,99991231,TEST@YAHOOO Message Type - HRMASTER02 Basic Type - HRMASTER02 Mapped Structure - E1BPHR0105 I am getting an