How to get ThreadLocal using executor?
I am using CompletionService for my producer/consumer problem.
ExecutorService executor = Executors.newFixedThreadPool(threadPollSize);
CompletionService<List<SomeObect>> completionService = new ExecutorCompletionService<List<SomeObect>>(executor);Once the executor spawns mutiple Threads I submit the tasks..
completionService.submit(new Callable<List<SomeObect>>() {
public List<SomeObect> call() throws IngestSystemException {
FileConnector connector = ThreadLocalFtpConnectionUtil.getThreadLocalFileConnector(getConnector().getFtpCredentials().getServerName(),
getConnector().getFtpCredentials().getUserName(),
getConnector().getFtpCredentials().getPassword(),
getConnector().getFtpCredentials().getRootDirectory());
Now ever Thread uses its own copy of FtpConnection...Hence ThreadLocal...Here is the ThreadLocal code
private static ThreadLocal<FtpConnector> threadLocal = new ThreadLocal<FtpConnector>();
* @param serverName
* @param userName
* @param password
* @param rootDirectory
* @return
public static synchronized FtpConnector getThreadLocalFileConnector(String serverName, String userName,
String password, String rootDirectory) throws IngestSystemException {
FtpConnector ftpConnector = null;
if (threadLocal.get() == null) {
ftpConnector = new FtpConnectorImpl(
new FtpCredentials(serverName,userName,password,rootDirectory));
try {
ftpConnector.open();
}catch (FileConnectionException e){
throw new Exception(String.format("Exception opening ftp connection for" +
" server [%s]" +
" username [%s]" +
" password [%s]" +
" root directory [%s]",
serverName,
userName,
password,
rootDirectory),e);
threadLocal.set(ftpConnector);
}else{
ftpConnector = threadLocal.get();
return ftpConnector;
* @return
public static synchronized void closeConnection(){
FtpConnector ftpConnection = null;
try {
ftpConnection = threadLocal.get();
ftpConnection.close();
}catch(FileConnectionException e){
throw new RuntimeException(String.format("Exception closing ftp connection for thread%s",Thread.currentThread()),e);
}Everything works fine...My problem I need to close all the ftp connections held by ThreadLocal for every Thread spawned by the executor; only after the executor is done..possibly at shutdown()
One option I got working is writing my own ThreadPoolExecutor and in this workerDone method I close the ftp connection.
* Perform bookkeeping for a terminated worker thread.
* @param w the worker
void workerDone(Worker w) {
final ReentrantLock mainLock = this.mainLock;
mainLock.lock();
try {
// close all the Ftp connections
ThreadLocalFtpConnectionUtil.closeConnection();
}But to get this to work I had to write my own RejectedExecutionHandler, ThreadPoolExecutor, and Executors.
Is there any other way to solve this problem?
Edited by: passtor on Oct 15, 2007 4:39 PM
My problem I need to close all the ftp connections held by ThreadLocal for every Thread spawned by the executor; only after the executor is done..possibly at shutdown()Then you can't use ThreadLocal. ThreadLocal data can only be accessed by the thread that put it there.
Similar Messages
-
In ABAP HR how to get job using position
In ABAP HR how to get job using position (Using Infotype 1001)
Hi anilkumar,
1. u have the position
u want the Job
2. In hrp1001 table
OTYPE = 'S' (for position)
OBJID = POSITION (AS ABOVE)
SCLAS = 'C' (for finding job)
<b> SOBID = XXXXXX (here u will get the JOB)</b>
regards,
amit m. -
How to get image using Http and how to save in Smulator
Hi guys,
Am working in black berry bold. i dont know how to get image using htp connection and one more thing i need to save this image in side simulator directory............. what are the specific API i should...
Guide me.........If you want the input image size you need to pass it in as parameters.
A discussion thread on this topic is:
http://forums.adobe.com/thread/29948
-- Daniel R. <[email protected]> http://danielr.neophi.com/ -
Hi out there. To capture a screen shot one uses: Command-Shift-3 or 4. I have done this for a long time. Now suddenly neither screen shot command works anymore. Suggestions how to get this useful function back? Thanks, Georgx
Command-Shift-3 and 4 works just fine on several Macs that I have here.
Try restarting your Mac....or post in the specific support area for your Mac model....for more advice.
https://discussions.apple.com/index.jspa -
Hi,
I have this xml file stored in operator.xml
<Operator>
<Customer>
<Name>sam</Name>
<Street>albert str.</Street>
<ZipCode>45454</ZipCode>
<City>NY</City>
<Country>USA</Country>
<EMailAddress>[email protected]</EMailAddress>
<MeterNumber>1000</MeterNumber>
<MeasuringUnit>kWh</MeasuringUnit>
<Reading>
<Month>1</Month>
<Value>900</Value>
</Reading>
<Reading>
<Month>2</Month>
<Value>725</Value>
</Reading>
<Reading>
<Month>3</Month>
<Value>950</Value>
</Reading>
</Customer>
</Operator>I have the following getter statements in my code:
String name=req.getName();
int month=req.getMonth();Now, I want to get value for particular customer (by checking name for equality with getter) and for particular month( by checking for equality with getter).
I have written the following statements:
final String filename="operator.xml";
SAXBuilder builder=new SAXBuilder(true);
Document doc=builder.build(filename);
Element root=doc.getRootElement();How to proceed further using JDOM. I am confused with getChild(), getChildText() etc.,
thanks,Obtain values with the JDom XPath class selectSingleNode and selectNodes methods.
SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser");
org.jdom.Document jdomDocument=saxBuilder.build(new File("c:/input.xml"));
org.jdom.Element zipcodeNode= (org.jdom.Element)(XPath.selectSingleNode(jdomDocument,"/Operator//Customer/zipCode")); -
How to get InitialContextFactory using RMI/IIOP without using weblogic.jar
Hi Robert
I know this is an old post. but I am interested in knowing how to get the
initial context using RMI/IIOP without the use weblogic specific classes
like weblogic.jndi.WLInitialContextFactory . If you have a code snippet that
you can provide as an example, it would be just great.
thanx in advance
Daya Sharma
See comments inline...
Stewart Wachs wrote:
I would like to get an initial context to Weblogic JNDI from a client.
code snippet:
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFacorty");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try {
Context ctx = new InitialContext(ht);
catch(...) {
This works fine when I include weblogic.jar (and other dependend weblogic
jar's) in the classpath.
Is there a way to access WL JNDI from a client without the weblogicclasses
in the classpath?If you are using WLS 6.1, you could use RMI/IIOP to do this but in general,
the
answer is no, you will need at least some of the weblogic classes on the
client.
If not, is there a lightweight jar available for distribution for client
JNDI connectivity?This is something in the works. In addition, a colleague and I are working
on
a white paper that describes the "Thin Client Options with WebLogic Server"
that we hope to make available in the not too distant future...
Are there any licencing issues with distributing the weblogic classes to
clients that need to access WL JNDI?No. WLS is licensed by the server so you are free to distribute
weblogic.jar
to your clients.
Hope this helps,
RobertTake a look at the RMI/IIOP section of our whitepaper "Small Footprint
Client options for BEA WebLogic Server" at:
http://dev2dev.bea.com/resourcelibrary/whitepapers.jsp?highlight=whitepapers
Daya Sharma wrote:
Hi Robert
I know this is an old post. but I am interested in knowing how to get the
initial context using RMI/IIOP without the use weblogic specific classes
like weblogic.jndi.WLInitialContextFactory . If you have a code snippet that
you can provide as an example, it would be just great.
thanx in advance
Daya Sharma
See comments inline...
Stewart Wachs wrote:
I would like to get an initial context to Weblogic JNDI from a client.
code snippet:
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFacorty");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try {
Context ctx = new InitialContext(ht);
catch(...) {
This works fine when I include weblogic.jar (and other dependend weblogic
jar's) in the classpath.
Is there a way to access WL JNDI from a client without the weblogic
classes
in the classpath?
If you are using WLS 6.1, you could use RMI/IIOP to do this but in general,
the
answer is no, you will need at least some of the weblogic classes on the
client.
If not, is there a lightweight jar available for distribution for client
JNDI connectivity?
This is something in the works. In addition, a colleague and I are working
on
a white paper that describes the "Thin Client Options with WebLogic Server"
that we hope to make available in the not too distant future...
Are there any licencing issues with distributing the weblogic classes to
clients that need to access WL JNDI?
No. WLS is licensed by the server so you are free to distribute
weblogic.jar
to your clients.
Hope this helps,
Robert -
How to get or use "kTextFrameOversetChangeMsg" as serviceid?
Hi all
I've developed a small plugin for handling textframe overflow. I've used service ids "kBeforeSaveDocSignalResponderService", "kBeforeSaveAsDocSignalResponderService". But actually I've to run it, only when overflow occurs.
Steven suggested to use "kTextFrameOversetChangeMsg". I tried, but I dont know exactly how to use it as service id. Could anyone suggest on this?
thanks in advance
A.HakkimThank u both. Pls suggest me how to get serviceid from "kTextFrameOversetChangedMsg".
-
How to get and use mouse information?
I want to write a simple program for getting mouse location, and if the location of the mouse is within an area, then a red dot show on the screen.
Could anyone please teach me how to get mouse location?
Thankshttp://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html
http://java.sun.com/docs/books/tutorial/uiswing/events/mousemotionlistener.html
http://java.sun.com/docs/books/tutorial/uiswing/events/mousewheellistener.html
Doh! Too slow!
Message was edited by:
DrLaszloJamf -
How to get iterator used on jsff from button clicked on jspx
Hi All,
I am using jdeveloper 11.1.1.5.
I have a bounded task flow and inside that I have a jsff and I have added one iterator in its bindings. Now I have dragged that jsff on my jspx page as a region.
I have a button on my jspx page I want to find the iterator of the jsff on button click.
How to find it.
Please help.
-- NavinKThanks Timo for your reply.
Does that mean We have to add the same iterator in the bindings of jspx as well ?
In my case I have added the iterator to my jspx page but I am getting the error described in InputText value is not getting updated in Iterator
Please help.
--NavinK -
How I get started using voice input with mac mail?
Just got a new Imac. have had Apple computers for a long time. Want to start using voice input with mail. How do I get started?
Apple's voice input options are the following:
Dictation
This allows you to speak a phrase and have the system enter it as text in any text field, be it a name and address form or a text editor like Pages or Word. The settings for this service are in the Dictation system preferences, and by default you activate it by pressing the Fn key twice in a row and then speak the desired phrase after you hear the bing sounds.
Speakable Items
This option allows you to somewhat control the Mac's interface elements by speaking key phrases to the system. This option is enabled in the Accessibility system preferences, and is at the bottom of the listed services. In here you can turn on the service and calibrate it to properly hear your voice, set a "listening key" (similar to the Fn key for Dictation), and then enable various command libraries. -
How to get bytes[] using jni functions
I am new to JNI and have a question. I have a java class which returns back bytes[]
I have the class jclass for the object and the jmethodid bytesMethodID which is mapped like this:
bytesMethodID = (*env)->GetMethodID(env, objcls, "bytes", "()[B");
now in the c impementation I have a stuct pointer
DESIGN_STRUCT *str= NULL;
How do I assign the bytes[] into this struct pointer? If I do the following:
str = (*env)->CallObjectMethod(env, obj, bytesMethod());
I get a "assignment from incompatible pointer type" if I change that to:
str = (*env)->CallBytesMethod(env, obj, bytesMethod());]
I get a "assignment makes pointer from integer without a cast"
My question is what JNI function do i use to get back a byte[]
Any help and pointers greatly appreciated.
Thanks,You should use CallObjectMethod() and cast the return value to a jbyteArray. Then you need to use a function like GetByteArrayElements() to actually retrieve the individual elements in that array.
God bless,
-Toby Reyelts
Check out the free, open-source, JNI toolkit, Jace - http://jace.reyelts.com/jace. -
HOw to get DatabaseMetaData using JPA
hi;
I am using ejb3 , jpa for database connectivity .is there any way to get the metadata about the database in JPA.
ie:- in JDBC we can use DatabaseMetaData for getting this. HOw can we get the Database Meta Data by using JPA.
Regards
IrshadIn addition to Gurvinder references, go over the productCatalog.xml or customCatalog.xml file to know the properties in each item-descriptor of ProductCatalog.
In your requirement skuid is same as repositoryId.
If you are using in jsp then use SKULookUp droplet to get the sku repositoryItem.
If you need it in java code then use catalogTools.findSKU(String skuid).
Peace
Shaik -
How to get SLA using Calendar rules?
How can I add 24hrs to the time using the calendar rules? For Example, If the Monday's date is given I need to get Tuesday's date as SLA. If I give Friday's date I need to get Monday's date as SLA. I have tried using
CalendarRule.computeDate(time,interval).
CalendarRule.add(time,interval).It works fine for the first senario.but not for the second senario. Could please help me how to achive this. The above senario should also count the user defined holidays.
Please help me with regards.
Thanks in advance
- NarasimhaHi,
Plz write the following logic it will help you
sla = 1;
Time start;
start = 'now';
Int count;
count = 0;
if(sla > 0) {
while (count < sla) {
if(calendarRule.isHoliday(time : start) == false &&
calendarRule.isWorkDate(time : start) == true) {
count = count + 1;
start = start + '1d';
start = start - '1d';
logMessage("inal Due Date for SLA (" + sla + " Day/s) is " + start.format("dd/MM/yyyy"));
I have hard coded the start time as well as sla. Please make the necessary changes.
Bibhu
Edited by: Bibhuti Bhusan on Sep 22, 2010 3:35 AM -
How to get last used IP addres of my stolen mac?
Hello, my mac was stolen. I was notified about address where it was used, also status changed to "Locked". How can I get last IP address of my mac, because it's the only way how I can help to police.
Unfortunately, there is only the information which shown to you by "Find My iPhone".
-
[Winsock BT] How to get phonebook using socket API
Hello,
I am writing an app to get phonebook from device.
I've connect to a device has PBAP service.
But after that, i don't know how to pull the phonebook to my local PC.
Any feedback is appreciated.
ULONG ulRetCode = 0;
int iCxnCount = 0;
char szData[CXN_TRANSFER_DATA_LENGTH] = {0};
SOCKET LocalSocket = INVALID_SOCKET;
SOCKADDR_BTH SockAddrBthServer = {0};
// Setting address family to AF_BTH indicates winsock2 to use Bluetooth sockets
// Port should be set to 0 if ServiceClassId is spesified.
SockAddrBthServer.addressFamily = AF_BTH;
SockAddrBthServer.btAddr = (BTH_ADDR) ululRemoteAddr;
SockAddrBthServer.serviceClassId = PhonebookAccessPseServiceClass_UUID;
// Valid ports are 1 - 31
SockAddrBthServer.port = 0;
LocalSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
connect(LocalSocket, (struct sockaddr *) &SockAddrBthServer, sizeof(SOCKADDR_BTH))
// what's the right request command??
send(LocalSocket, Command, strlen(Command)*sizeof(wchar_t)+1, 0);
recv(LocalSocket, recvbuf, recvbuflen, 0);// Prepare all necessary command
char ConnectCommand[255] = {
0x80, //0x00,0x03};
0x00,0x1a, // 2 packet length
0x10, // 1 version number(1.0)
0x00, // 1 connect flag (must be 0 in sending side)
0x08,0x00, // 2 Maximum OBEX packet length
0x46, //Target header identifier
0x00,0x13, // length of Target header identifier
0x79,0x61,0x35,0xf0,0xf0,0xc5,0x11,0xd8,0x09,0x66,0x08,0x00,0x20,0x0c,0x9a,0x66 //PBAP UUID
unsigned char GetCommand[] = {
0x83,
0x00,0x5d,
0xcb, // HI for ConnectionId header
0x00,0x00,0x00,0x01, // Connection ID
0x01, // HI for Name header
0x00,0x2b, // length of Name header
0x00,0x53,0x00,0x49,0x00,0x4d,0x00,0x31,0x00,0x2f,0x00,0x74,0x00,0x65,0x00,0x6c,0x00,0x65,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x2f,0x00,0x70,0x00,0x62,0x00,0x2e,0x00,0x76,0x00,0x63,0x00,0x66,0x00,0x00, // SIM1\telecom\pb.vcf
0x42, // HI for Type header
0x00,0x12, // length of empty Type header
0x78,0x2d,0x62,0x74,0x2f,0x70,0x68,0x6f,0x6e,0x65,0x62,0x6f,0x6f,0x6b,0x00, // x-bt/phonebook
0x4c, // HI for App.Parameter header
0x00,0x18, // length of App.Parameter header
0x06,0x08,0x00,0x00,0x00,0x3f,0xff,0xff,0xff,0xff,0x07,0x01,0x00,0x04,0x02,0xff,0xff,0x05,0x02,0x00,0x00
unsigned char ContinueGetCommand[] = {
0x83,
0x00,0x03
//set to root
unsigned char SetPathCommand[] = {
0x85, // opcode
0x00,0x0d, // packet length
0x02, // flag
0x00, // constants(always zero)
0xcb, // HI of ConnectionID
0x00,0x00,0x00,0x02, // ConnectionID (diff at each connect)
0x01, // HI of Name
0x00,0x03 // length of Name
//set to telecom
unsigned char SetPathCommand2[] = {
0x85,
0x00,0x1d,
0x02,0x00,
0xcb,
0x00,0x00,0x00,0x02,
0x01,
0x00,0x13,
0x00,0x74,0x00,0x65,0x00,0x6c,0x00,0x65,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x00
//set to PB
unsigned char SetPathCommand3[] = {
0x85,
0x00,0x13,
0x02,0x00,
0xcb,
0x00,0x00,0x00,0x02,
0x01,
0x00,0x09,
0x00,0x70,0x00,0x62,0x00,0x00
//vcard-listing:phonebook size
unsigned char GetVLCommand[] = {
0x83, // opcode
0x00,0x2f, // packet length
0xcb, // HI of ConnectionID
0x00,0x00,0x00,0x02, // ConnectionID
0x42, // HI of Type
0x00,0x16, // length of Type
0x78,0x2d,0x62,0x74,0x2f,0x76,0x63,0x61,0x72,0x64,0x2d,0x6c,0x69,0x73,0x74,0x69,0x6e,0x67,0x00,
0x01, // HI of Name
0x00,0x03, // length of Name
0x4c, // App. Parameter
0x00,0x0e, // length of App.Parameter
0x01,0x01,0x01,0x04,0x02,0x00,0x00,0x05,0x02,0x00,0x01
//vcard-listing
unsigned char GetVLCommand2[] = {
0x83,
0x00,0x2f,
0xcb,
0x00,0x00,0x00,0x02,
0x42,
0x00,0x16,
0x78,0x2d,0x62,0x74,0x2f,0x76,0x63,0x61,0x72,0x64,0x2d,0x6c,0x69,0x73,0x74,0x69,0x6e,0x67,0x00,
0x01,
0x00,0x03,
0x4c,
0x00,0x0e,
0x01,0x01,0x01,0x04,0x02,0xff,0xff,0x05,0x02,0x00,0x00
//get vcf
unsigned char GetVCFCommand[] = {
0x83,
0x00,0x39,
0xcb,
0x00,0x00,0x00,0x02,
0x01,
0x00,0x13,
0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x2e,0x00,0x76,0x00,0x63,0x00,0x66,0x00,0x00, //000.vcf
0x42,
0x00,0x0e,
0x78,0x2d,0x62,0x74,0x2f,0x76,0x63,0x61,0x72,0x64,0x00,
0x4c,
0x00,0x10,
0x06,0x08,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x84,0x07,0x01,0x00
unsigned char DisconnectCommand[] = {
0x81,
0x00,0x08,
0xcb,
0x00,0x00,0x00,0x02
Successfully download phonebook from Htc M7
Maybe you are looking for
-
I am not sure where to put this but I would like individual tones for all my email accounts
-
BitLocker Drive Encryption, Access Issues
I encrypted my external hard drive and save the recovery key to a thumb drive. Now I cant access my external drive. I get an error message that says that the key I have entered does not match this drive. Can anyone help?
-
Looking forward to seeing improvements in the accessibility tools for Acrobat. Allow customization of this tool so that you can add custom Tag. Alternatiely, add the List Label and LBody tags to the ROT. I manually Tag Lists more than anything els
-
I recently purchased an album from itunes. Most of the tracks recoded only partially. How cand I re-download the purchase from itunes and correct the problem?
-
Upgradation of 11.0.3 (vis) to 11i any documentation
Dear Friends, I want to upgrade vis 11.0.3 to 11i can you please let me know from where to start. Regards, Rajanish Joshi null