Example usage for java.util.concurrent ExecutionException printStackTrace

List of usage examples for java.util.concurrent ExecutionException printStackTrace

Introduction

In this page you can find the example usage for java.util.concurrent ExecutionException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:FutureTest.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
    String directory = in.nextLine();
    System.out.print("Enter keyword (e.g. volatile): ");
    String keyword = in.nextLine();

    MatchCounter counter = new MatchCounter(new File(directory), keyword);
    FutureTask<Integer> task = new FutureTask<Integer>(counter);
    Thread t = new Thread(task);
    t.start();/*from   ww  w .j av a 2 s .c om*/
    try {
        System.out.println(task.get() + " matching files.");
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
}

From source file:ThreadPoolTest.java

public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
    String directory = in.nextLine();
    System.out.print("Enter keyword (e.g. volatile): ");
    String keyword = in.nextLine();

    ExecutorService pool = Executors.newCachedThreadPool();

    MatchCounter counter = new MatchCounter(new File(directory), keyword, pool);
    Future<Integer> result = pool.submit(counter);

    try {//from ww w .jav  a  2s . co m
        System.out.println(result.get() + " matching files.");
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
    }
    pool.shutdown();

    int largestPoolSize = ((ThreadPoolExecutor) pool).getLargestPoolSize();
    System.out.println("largest pool size=" + largestPoolSize);
}

From source file:com.sina.dip.twill.HelloWorldClassDependent.java

public static void main(String[] args) {
    String zkStr = "localhost:2181";

    YarnConfiguration yarnConfiguration = new YarnConfiguration();

    final TwillRunnerService twillRunner = new YarnTwillRunnerService(yarnConfiguration, zkStr);

    twillRunner.start();//w  ww .  j  a  v  a 2  s . c o m

    String yarnClasspath = yarnConfiguration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
            "/usr/lib/hadoop/*,/usr/lib/hadoop-0.20-mapreduce/*,/usr/lib/hadoop-hdfs/*,/usr/lib/hadoop-mapreduce/*,/usr/lib/hadoop-yarn/*");

    List<String> applicationClassPaths = Lists.newArrayList();

    Iterables.addAll(applicationClassPaths, Splitter.on(",").split(yarnClasspath));

    final TwillController controller = twillRunner.prepare(new HelloWorldApplication())
            .withApplicationClassPaths(applicationClassPaths)
            .withBundlerClassAcceptor(new HadoopClassExcluder()).start();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                Futures.getUnchecked(controller.terminate());
            } finally {
                twillRunner.stop();
            }
        }
    });

    try {
        controller.awaitTerminated();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    Callable<Object> badTask = () -> {
        throw new RuntimeException("Throwing exception from task execution...");
    };/* ww w . j  av a  2 s .  com*/
    ExecutorService exec = Executors.newSingleThreadExecutor();
    Future submittedTask = exec.submit(badTask);
    try {
        Object result = submittedTask.get();
    } catch (ExecutionException e) {
        System.out.println(e.getMessage());
        System.out.println(e.getCause().getMessage());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    exec.shutdown();
}

From source file:Main.java

/**
 * Waits for all threads to complete computation.
 * /* ww w .  java  2 s .c  om*/
 * @param futures
 */
public static void waitForCompletion(Future<?>[] futures) {
    int size = futures.length;
    try {
        for (int j = 0; j < size; j++)
            futures[j].get();
    } catch (ExecutionException ex) {
        ex.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Waits for all threads to complete computation.
 * //from  w  w  w  . j  a v  a 2s. c  om
 * @param futures
 */
public static void waitForCompletion(Future<?>[] futures) {
    int size = futures.length;
    try {
        for (int j = 0; j < size; j++) {
            futures[j].get();
        }
    } catch (ExecutionException ex) {
        ex.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:se252.jan15.calvinandhobbes.project0.IIScCampusMapSDB_GETService.java

@GET
@Produces(MediaType.APPLICATION_JSON)// ww  w. j  a v  a  2  s .  co  m
public static Response IIScCampusMapGet(
        @DefaultValue("AllCategories") @QueryParam("category") String category) {
    LayerInfo[] layers = null;
    try {
        layers = categoryCache.get(category);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return Response.ok(layers, MediaType.APPLICATION_JSON).header("Access-Control-Allow-Origin", "*").build();
}

From source file:se252.jan15.calvinandhobbes.project0.IIScCampusMapRDBMS_GETService.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from w ww. ja va  2s  . c o m*/
public static Response IIScCampusMapGet(
        @DefaultValue("AllCategories") @QueryParam("category") String category) {
    Object[] layers = null;
    try {
        layers = categoryCache.get(category);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return Response.ok(layers, MediaType.APPLICATION_JSON).header("Access-Control-Allow-Origin", "*").build();
}

From source file:it.uniroma2.foundme.studente.CourseActivity.java

public static void setFields(String cfu, String prof2, String prof3, int n) {
    course.setText(Title + " " + cfu + " CFU");
    prof.setText(Prof);/*from ww  w  .  ja  v  a 2s.  c om*/
    ass1.setText(prof2);
    ass2.setText(prof3);

    if (n != 0)
        notifica.setChecked(true);
    else
        notifica.setChecked(false);
    notifica.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                try {
                    manageNotification(Variables_it.ENABLE, Sid, Title, Prof);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    manageNotification(Variables_it.DISABLE, Sid, Title, Prof);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

From source file:it.uniroma2.foundme.studente.UnFollowCourseActivity.java

public static void alertMessage(final String info) {
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                extractData(info);/* w  ww . ja  v a  2s .c o  m*/
                //new deleteCourse().execute(title, prof, Sid)
                try {
                    managefollowing(title, prof, Sid);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                break;
            case DialogInterface.BUTTON_NEGATIVE:
                break;
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(Variables_it.UNFOLLOW_REQUEST).setNegativeButton(Variables_it.NO, dialogClickListener)
            .setPositiveButton(Variables_it.YES, dialogClickListener).show();
}