Throttling Submission Of Tasks To A ThreadPoolExecutor

Jun 4, 2014

I have a library that uses a ThreadPoolExecutor, backed by a bounded queue.

We submit a large number of tasks to this executor, constantly polling an external dependency for new work. However, this executor has a fixed size. When a ThreadPoolExecutor is busy, it queues up to the blocking queue's capacity tasks in its blocking queue, at which point it starts rejecting tasks.

What I'd rather do, instead of requesting more work, and then throwing it out, is to detect that we're totally busy and stop requesting work until a thread frees up.

Now, I know that one approach is to rewrite the workers such that they are infinite loops, who poll for work when they're finished. Due to the large number of consumers of this library, this is not an option.

I have come up with two other solutions.

1) This is one that I know will work, which is to use a semaphore or other concurrent counter to track how many tasks I have submitted, and stop requesting more work when that semaphore is out of permits. The processors release a permit when they complete (whether due to exception or success).

2) The other option, since I know this is a ThreadPoolExecutor, is way simpler, but also is something I'm not sure is reliable.

I can compare executor.getActiveThreads() + executor.getQueue.size() to the maximum number we can handle before rejecting (maxThreads + queueSize). This change is far simpler, but I'm not sure if those calls are a reliable way of counting the current work.

View Replies


ADVERTISEMENT

Print Out Statement After Executing To ThreadPoolExecutor?

Jul 26, 2014

I'm trying to make a statement of elapsed time print out after I've executed everything with a ThreadPoolExecutor. What happens is that instead of printing out after all the iterations within the for each loop are done, it prints out the elapsed statement in the middle of the iterations or even in the beginning of the whole execute() method. Here is my code:

package com.atem;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
public final class Example {

[Code]...

View Replies View Related

JSP :: Getting Value On Form Submission On Same Page

Oct 31, 2014

I am showing a jsp page asking user to select a course from dropdown <select> options fetched from database.When user selects a value and click on submit button , I want to show the details of the course on the same page .how can I get the value of user selection on the same jsp page.Then I can make a query using that value and show other details on the same page.

View Replies View Related

Due Date And Submission Features

Mar 7, 2014

Click the title of the assignment to see Due Date and submission features.

Write a program that determines the number of Dots in an input line. Read in the line into a string. Next use the charAt( ) method in a loop to access the characters one by one.

Your program should have comments towards the top of the program. Copy at least two sample runs and paste as a comment at the bottom of the program. At least one sample run would be a string that has a few blanks. At least one sample run would be a string that does not have any blanks.

Use Assign5_{your last name} as the name of the program.

Submit one file, the Java file only.

As a general rule; no credit is given to work submitted late. If any consideration is given for partial credit; such decision will be made at the end of the semester; at the point in time when the Course Letter grade is determined.

View Replies View Related

Applets :: Encrypt Password Before Submission Of Form

Mar 23, 2013

I have an encryption utility class. Can i use it some how to encrypt password before submitting form? I heard it can be done using applet.

View Replies View Related

Servlets :: Submission Parameter Order Maintained?

Nov 27, 2014

Is there anything in the HTML specification about whether submitted GET or POST parameters must retain their order? E.g. In the following is there anything in the spec that says the following data should be returned in the order they appear in the HTML code. And, most importantly, is there anything that says the firstName and surname fields should actually match up with each other, i.e. the order can change but in the same way for each field?

<form>
<table>
<tr><td><input type="text" name="firstName"/></td><td><input type="text" name="surname"/></td></tr>
<tr><td><input type="text" name="firstName"/></td><td><input type="text" name="surname"/></td></tr>
<tr><td><input type="text" name="firstName"/></td><td><input type="text" name="surname"/></td></tr>
<tr><td><input type="text" name="firstName"/></td><td><input type="text" name="surname"/></td></tr>
<tr><td><input type="text" name="firstName"/></td><td><input type="text" name="surname"/></td></tr>
<tr><td><input type="text" name="firstName"/></td><td><input type="text" name="surname"/></td></tr>
<table>
</form>

View Replies View Related

Java Servlet :: Multiple Time Submission Of A Form Automatically In Struts

Jan 10, 2013

I have a button in jsp, when the onclick event is fired, it will send the request to someaction.do to generate a report and display that report in a new window.

After clicking the button to generate the report, in the business class a sql query is getting executed.

If the query result has less data, then I don't have any problem, I could view my report page.

If the query result has more data, then the query takes at least 5-6mins to complete. However, before the query completes its execution, the same request is automatically invoked again. Due to this the report is not getting generated because [...of the multiple requests?], the browser shows an Internet Explorer error and ends up at a blank page.

No exception is thrown and the only place I could find the place of query execution it stops and starts as a new request from web.xml with Servlet Filters, Action.

Note: For a single .do request, the request is getting repeated for 3 times. Overlapping of request also takes place.

View Replies View Related

Swing/AWT/SWT :: JButton Does Not Do All Tasks

Aug 3, 2014

I have a jButton that when the action perform runs it only does part of the tasks some of the code doe not appear to run and i just can not figure out why i have tried wrapping parts of it in an if statement and it still do not run so here is the code behind the button:

in the code the parts that do not run are jTextField10.setText("Working Please Wait"); and jButton15.setVisible(false);

what i am expecting to happen is the text field has the words Working Please Wait placed in it , this does not happen and the button should be hidden to prevent it being clicked a second time again this does not happen

the rest of the code works as expected

InputStream inStream;
OutputStream outStream;
try {
File afile = new File("C://templates//amendments.xls");
File bfile = new File("C://amendments.xls");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);

[code]....

View Replies View Related

How To Perform Tasks Listed In Text File

Feb 12, 2015

This has three different classes in a package and the program itself is supposed to read and perform operations obtained from a txt file. However, I'm not even sure how to get it to perform the operations from the text file. I know that it can read the file as I was able to get the program to print the text found in the file when I ran the program with a test print to make sure that all content was being read. However, I am clueless when it comes to how to get the program to look at the text as commands.

Here is the piece of code that I am not sure where to go from as far as telling the program to read the text and perform the tasks listed.

public static void doTVoperations(){
File operations = new File("operations.txt");
if(operations.exists())
try{
Scanner n = new Scanner(operations);

[Code] ....

View Replies View Related

Servlets :: Offline Tasks In Java Web Application

Feb 11, 2014

I am on developing a web application (using struts). So most of my web application use cases are reading and presenting data to the users.

But i need to write the another set of programs to keep on reading the data from another data bases and update my database. I have list of timings at which i should read the data from each of other sites (i.e. i know when the other databases gets updated information). Its almost every 20 mins..

Now i want to design the app.

1. Should i include the data read programs as part of my Web application ( means runs in same server JVM) and make the threads as daemon threads..?
2. Should i write another application (offline application) runs out of server in another JVM ?

View Replies View Related

Automated Web Browser To Perform Specific Tasks

Jul 14, 2014

I need to know how to automate a web browser (either Chrome, Firefox or Safari) to perform the following task.

Take a word from a .txt file housed on my hard drive,

1) put it into a search engine,
2) load the results,
3) click on/ open the first result,
4) open up an new tab and perform steps 1-3 again but with the next word from the .txt file. 4-5 second pauses are needed in between each step.

Additionally, I would like to automate the browser to close all the open tabs when a full stop is pulled from the .txt file.

I am using a macbook and 10.6.8 OS.

View Replies View Related

Open Source Java API For Creating Tasks To MS Outlook?

May 28, 2014

I am looking for pure java API to be able to create/read outlook tasks.

Any open source API's available for the same.

View Replies View Related

How To Get Program To Perform Tasks Listed In Text File

Feb 12, 2015

This has three different classes in a package and the program itself is supposed to read and perform operations obtained from a txt file. However, I'm not even sure how to get it to perform the operations from the text file. I know that it can read the file as I was able to get the program to print the text found in the file when I ran the program with a test print to make sure that all content was being read. However, I am clueless when it comes to how to get the program to look at the text as commands.

Here is the piece of code that I am not sure where to go from as far as telling the program to read the text and perform the tasks listed.

public static void doTVoperations(){
File operations = new File("operations.txt");
if(operations.exists())
try{
Scanner n = new Scanner(operations);
while(n.hasNext()){
String readOperations = n.nextLine();
String [] command = readOperations.split("[
]");
}
n.close();
}
catch (FileNotFoundException e){
System.out.print("Error...TV in need of repair!");
}

View Replies View Related

Prompt A User To Enter Three Tasks And Their Priorities In A Driver

Oct 31, 2014

My full instructions are to Design a Java interface called Priority that includes two methods and two constants. The methods are setPriority and getPriority. The constants are MIN_PRIORITY with value 1 and MAX_PRIORITY with value 6. The interface should define a way to establish numeric priority among a set of objects. Design and implement a class called Task that represents a task (such as on a to-do list) that implements the Priority interface. Assume that Task has two attributes (instance data): name and priority. Define the Task constructor to accept and initialize the name of the task. Each newly created Task should have priority equal to MIN_PRIORITY (the constructor should initialize priority to MIN_PRIORITY). Priorities can be changed using setPriority method. Create a driver class TaskDriver that should do the following: prompt the user to enter three tasks and their priorities, and then print the tasks in the order of decreasing priorities. If the user enters an invalid priority that is less than MIN_PRIORITY or greater than MAX_PRIORITY, then the user should be asked to enter priority again until a valid priority value is entered.

So far I have:

public interface Priority
{
public void setPriority(int level);
public int getPriority();

[Code].....

View Replies View Related

Schedule More Tasks Side By Side

Aug 16, 2014

I'm using SchedulerExecutorServices to Schedule a task. My Question is how can i schedule more than one task side by side:

Here is what I'm doing:

public class Scheduler {
public Scheduler(Runnable thread, int startAfter, int iterateAfter, TimeUnit timeUnit, int length) {
ScheduledExecutorService scheduler = Executors
.newSingleThreadScheduledExecutor();
final ScheduledFuture<?> timeHandle = scheduler.scheduleAtFixedRate(

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved