How to finish thread, listening to a socket input?
Hello!
Can anybody tell me how to correctly interrupt/close thread, listening to a socket input from a server?
I have a separate thread which listens to an input from server. When a client disconnects from server, it should be closed. I do:<p>
<code>
Thread th=new Thread(myRunnable);
th.start();
Thread old=th;
th=null;
old.interrupt();
</code>
But nevertheless I get a SocketException. This is because in thread I use<p>
<code>
public void run()
MyMessage incoming=null;
while((incoming=(MyMessage)reader.readObject())!=null)
</code>
and I/O methods are blocking current thread's running process. Is this technics correct? Any other suggestions?
Thanx.
There have been issues with achieving consistent interruption of I/O across all platforms. The recommended approach seems to be to close the socket that the other thread is using, rather than interrupting the other thread.
If you first set a flag (declare it volatile) before closing the socket, you can use the fact that this flag is set as an indication in the other thread that the exception it gets should just be ignored.
Sylvia.
Similar Messages
-
How to use threads to reconnect a socket to a server in TCP/IP
I want to know how to reconnect a socket to a server in TCP.
Actually i wanted to do reconnection whenever a SocketException for broken connection etc. is thrown in my code. This I want to do for a prespecified number of times for reconnection in case of broken connection.When this number decrements to zero the program will exit printing some error message. I was planning to use threads by way of having some Exception Listeners but i am not sure How?
Any suggestions will be really helpful..
please help.
Edited by: danish.ahmed.lnmiit on Jan 28, 2008 2:44 AMI want to know how to reconnect a socket to a server in TCP.There is no reconnect operation in TCP. You have to create a new Socket.
-
How to use java to listen to a socket?
i want to create a listener to monitor the input and output of a very socket,i don't know which classes can be used.
thk u very much!!!!!!You can't create a socket in java to 'monitor the output'. At least not in the general sense.
In the general sense this is usually referred to as raw sockets and the default java does not do that. You can however, do it via JNI. If that is what you had in mind then look at http://www.goto.info.waseda.ac.jp/~fujii/jpcap/index.html
If this isn't what you are looking for then provide a bit more detail about what you will be monitoring. -
URGENT: How to run threads in sequence?
Dear experts, I am new to writing threads. I would like to know how to run threads in sequence? How do I know when a thread finishes its task?
In the following code, classes Process_A(), Process_B(), Process_C() and Process_D() are subclasses of Class Thread.
I'd like to know if I am using the join() function correctly? My intention is to wait for the previous process to finish before running the current process.
Could anyone kindly give me some solutions on how to run the processes in sequence?
Thanks!!
=============================================================
Thread process;
Vector process_names = new Vector();
process_names.add("a");
process_names.add("b");
process_names.add("c");
for(int i=0; i<process_names.size(); i++)
String process_name = (String) process_names.elementAt(i);
if(process_name.equals("a"))
process = new Process_A();
else if(process_name.equals("b"))
process = new Process_B();
else if(process_name.equals("c"))
process = new Process_C();
else if(process_name.equals("d"))
process = new Process_D();
timer = new javax.swing.Timer(1000, new ProcessListener());
timer.start();
// ProcessListener()
class ProcessListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
if(process!=null)
if(process.isAlive())
try
process.join();
catch(Exception ex)
ex.printStackTrace();
process.start();just look at this simple example u will get to know how to use join method
This does exactly what u want
class callme
void call(String msg)
System.out.println("["+msg);
Try
Thread.sleep(1000);
catch(InterruptedException e)
System.out.println("interrupted");
System.out.println("]");
class caller implements Runnable
String msg;
Callme target;
Thread t;
Public Caller(Callme targ, String s)
target=targ;
msg=s;
t=new Thread(this);
t.start();
public void run()
target.call9msg);
class Synch
public static void main(String arg[])
Callme target=new Callme();
Caller ob1=new Caller(target,"hello");
Caller ob2=new Caller(target,"Synchronized");
Caller ob3=new Caller(target,"world");
Try
ob1.t.join();
ob2.t.join();
ob3.t.join();
catch(InterruptedException e)
System.out.println("interrupted");
waiting for dukes -
GC Cause: 'Artifical: Cleaning up Finished Threads' (strange behaviour)
Hi everybody,
we have experiencing an strage issue after increasing our heap size and nursery in Production from
-Xms2816M -Xmx2816M -Xns550M to -Xms4096M -Xmx4096M -Xns1024M
We need to resize this because a new application is being promoted, and we have tested it in Pre-PRO
The thing is that after the new size and before deploying the new app,
all the 'Old Collection Reasons' are due to 'Artifical: Cleaning up Finished Threads' and the top of the HEAP (4GB) is never reached
A sample:
[gcpause][Wed Feb 27 22:29:26 2013][01719] [OC#621] [---] 1498,525 ms (611967,663000-611969,161000) OC
[gcpause][Wed Feb 27 22:29:26 2013][01719] [OC#621] [con] 0,004 ms (611967,663000-611967,663000) OC:PreGC
[gcpause][Wed Feb 27 22:29:26 2013][01719] [OC#621] [pau] 1453,742 ms (611967,663000-611969,116000) OC:Main
[gcpause][Wed Feb 27 22:29:26 2013][01719] [OC#621] [con] 43,411 ms (611969,118000-611969,161000) OC:PostGC
[memory ][Wed Feb 27 22:29:26 2013][01719] [OC#621] 611967,663-611969,161: OC 2982855KB->1227524KB (4194304KB), 1,499 s, sum of pauses 1453,742 ms, longest pause 1453,742 ms.
After examinig the correponding JFR we haven't any issue or hotspot in the code that could justify this behaviour, in fact the same that works right with 2,8 GB HEAP
Googling hasn't given us any answer and the Support mates are requiring us some more information, but they say this is normal (something that I don't agree at all)
Any suggestion will be welcome ... thanks in advance
We're running:
java version "1.5.0_26"
Java(TM) Platform, Standard Edition for Business (build 1.5.0_26-b03)
Oracle JRockit(R) (build R28.1.1-14-139783-1.5.0_26-20101206-0241-linux-x86_64, compiled mode)
and:
HT is: not supported by the CPU, not enabled by the OS, not enabled in JRockit.
CPU: Intel Core 2 SSE SSE2 SSE3 SSSE3 SSE4.1 Core Intel64
Vendor: GenuineIntel
Family: Core 2
Model: Core 2
Name: Intel(R) Xeon(R) CPU X7460 @ 2.66GHz
Sockets: 4
Cores: 24
HWThreads: 24
Supports: On-Chip FPU
Supports: Virtual Mode Extensions
Supports: Debugging Extensions
Supports: Page Size Extensions
Supports: Time Stamp Counter
Supports: Model Specific Registers
Supports: Physical Address Extension
Supports: Machine Check Exceptions
Supports: CMPXCHG8B Instruction
Supports: On-Chip APIC
Supports: Fast System Call
Supports: Memory Type Range Registers
Supports: Page Global Enable
Supports: Machine Check Architecture
Supports: Conditional Mov Instruction
Supports: Page Attribute Table
Supports: 36-bit Page Size Extension
Supports: the CLFLUSH Instruction
Supports: the Debug Trace Store feature
Supports: ACPI registers in MSR space
Supports: Intel Architecture MMX Technology
Supports: Fast Float Point Save and Restore
Supports: Streaming SIMD extensions
Supports: Streaming SIMD extensions 2
Supports: Self-Snoop
Supports: Hyper Threading
Supports: Thermal Monitor
Supports: Streaming SIMD Extensions 3
Supports: 64-bit DS Area
Supports: MONITOR/MWAIT instructions
Supports: Virtual Machine Extensions
Supports: Enhanced Intel SpeedStep technology
Supports: Thermal Monitor 2
Supports: Supplemental Streaming SIMD Extensions 3
Supports: CMPXCHG16B
Supports: xTPR Update Control
Supports: Perfmon and Debug Capability
Supports: Direct Cache Access
Supports: Streaming SIMD extensions 4.1
Supports: LAHF/SAHF instruction support
Supports: SYSCALL/SYSRET
Supports: Intel 64 Architecture
[memory ][Wed Feb 20 20:29:57 2013][01719] Running with 32 bit heap and compressed references supporting 32GB heap.
[memory ][Wed Feb 20 20:29:57 2013][01719] GC mode: Garbage collection optimized for throughput, strategy: Generational Parallel Mark & Sweep."as I understand GcTrigger only applis for concurrent GC, and in fact we are having genpar (parallel)"
Yep, "The garbage collector ignores the -XXgcTrigger value when it runs both parallel mark and parallel sweep, for example if you specify -Xgc:singlepar or -Xgc:genpar on the command line."
Why not set a dynamic collection scheme (http://docs.oracle.com/cd/E15289_01/doc.40/e15062/optionx.htm#i1011879):
throughput - The garbage collector is optimized for application throughput. This means that the garbage collector works as effectively as possible, giving as much CPU resources to the Java threads as possible. This might, however, cause nondeterministic pauses when the garbage collector stops all Java threads for garbage collection.The throughput priority should be used when non-deterministic pauses do not impact the application's behavior.
pausetime - The garbage collector is optimized for short pauses. This means that the garbage collection works concurrently with the Java application when necessary, in order to avoid pausing the Java threads. This inflicts a slight performance overhead to the application, as the concurrent garbage collector demands more system resources (CPU time and memory) than the parallel garbage collector that is used for optimal throughput. The target pause time is by default 500 msec. To change the default pause target, see -XpauseTarget.
On an application server going for throughput gives good results, when you want to reduce the stop-the-world times it might be beneficial to use pausetime with an appropriate pausetarget.
"...we need to increase HEAP size to cover application expectations"
It should be fine to increase the heap size (we are running JRockit with 16G in certain environments, with the pausetime as the dynamic garbage collection setting), i.e.,
-Xms16g -Xmx16g -Xns1024m -Xgc:pausetime -XpauseTarget:200ms (in this case the application contains a lot of session data which is placed in the old generation hence
the choice for 16G) as long as you keep the live data below 2/3 of the heap, the collection time introduced should be near the 200millis.
http://middlewaremagic.com/weblogic/?page_id=7132 (contains a bunch of posts on JVM tuning) -
How to find the listener port on windows?
Hi Friends,
We have a client who is still using Oracle 8.0.6 on NT 4.0
I have a laptop with oracle client 10g.
I want to connect to the NT database to check it.
How do I know what port does the listener used ? what is the command to run at the c:\ command prompt?
I tried> c:\ lsnrctl stat but the command is not recognized
I tried to find the lsnrctl and bin but there is not.
Please help
Thanks a lotytterp2009 wrote:
Please help.. and please do NOT post [duplicate posts|http://forums.oracle.com/forums/thread.jspa?threadID=935282&tstart=0]
How to find the listener port on windows?The Internet Protocol stack comes with a number of utilities - one of these, called netstat, is very useful to determine which processes are doing what to which IP ports on that platform. Unfortunately, different flavours are implemented. So the Windows one does not support the parameters and output than the Unix/Linux one.
You can use the following on Windows (run it via a command console) to see what processes are listening on what address and port number:
c:\> netstat -n -a -p tcp
-n = display IP addresses and ports in numeric format
-a = list all ports (including ones used for listening
-p tcp = only display protocol entries for TCP An Oracle listener entry should look something as follows:
Proto Local Address Foreign Address State
TCP 0.0.0.0:1521 0.0.0.0:0 LISTENINGSeeing IP +0.0.0.0+ means that the Listener is accepting connections on all your network interfaces - which is standard. The port number is typically 1521. The foreign address is meaningless for a port in listening state.
PS. Why not simply check the listener.ora configuration file? Because what is actually happening may not be what you thought you configured to happen.. -
Can't figure out how to finish restoring icloud to my new iphone 5s
Just left Apple store, and they started restoring my icloud. Choice between Later/Finish Restoring. I chose "Later" to get to messages. Now I'm home and can't figure out how to finish restoring. Went to settings, then icloud and could not find anything to continue the restoring. I'm connected to my home wi-fi now, just need help to finish restoring.
It should resume automatically. Make sure it's connected to wifi and your charger.
If it doesn't, go to Setting>iCloud>Storage & Backup and tap Stop Restoring at the bottom. Then go to Settings>General>Reset, tap Erase All Content and Settings, go through the setup screens on your device and when given the option, choose Restore from iCloud backup and follow the prompts. This will start the restore over. -
hey how are you guys listen i have an iphone 4s the one i use with the H20 CARRIEr and i trying to enable the option call forwarding and when i type tho number i go back and i notice to the call forwarding it turning off as soon i back to the main menu ?
There are a lot of posts in the forums today with people having problems with iMessage. There was also a published outage yesterday, so it's possible there are still some issues that may be impacting you both.
I would just wait it out - I'm sure it will be sorted out soon. -
How to start a Listener in Windows XP
When I loggin into the DB from EM, I got the message
SQLException
IO : The Network Adapter could not establish the connection
And when I enter the following from prompt
lsnrctl startStarting tnslsnr: please wait...
Failed to start service, error 3.
TNS-12536: TNS:operation would block
TNS-12560: TNS:protocol adapter error
TNS-00506: Operation would block
32-bit Windows Error: 997: Unknown error
and >> tnsping db_name
Used parameter files:
G:\oracle\product\10.1.0\Db_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = nutri)))
TNS-12541: TNS:no listener
I do not know what is the problem.
Actually I previously install the oracle 10g twice and uninstall it.
But I observe from management console that the listener service on my PC would not be removed.
They are OracleOraDb10g_home1TNSListener and OracleOraDb10g_home2TNSListener.
I try to restart they but failed.
How could I fix this fatal problem.
Thanks a lotThanks for your reply
I had remove all listeners but in under WindowsXP, the listenr services still still exist.
Previously installed:
OracleOraDb10g_home1TNSListener
OracleOraDb10g_home2TNSListener
Now I am using this one:
OracleOraDb10g_home3TNSListener
My problem is that how to remove the listener services used by previously Oracle DB. -
How to use threads in JSP???
hello
i want to use threads with JSP.
i want to write a jsp page which will
start 2 different threads. the 1st thread should just display a message and the second page should redirect this page to another jsp page.
till the redirection is goin on, the message should be displayed in the browser from the 1st thread.
i dont know actually how to use threads in JSP by implementing the Runnable insterface, if not m then how do i do it ??
thanx
Kamal JaiWhy do you want to use threads to do this ??
If you write a message and do a redirection, the message will be displayed until the other page will be loaded into the browser...
I already launched a thread from a JSP but it was for a four hour process where the user can close his browser windows. -
How can I continue listening to a YouTube video while using another app?
How can I continue listening to a YouTube video while using another app?
How can I continue listening to a YouTube video while using another app?
-
How to kill threads in obiee server
Can some one please tell me how to kill threads in OBIEE server
944632 wrote:
Thanks for the prompt reply. your answer is helpful. Here is my problem.
I am an OBIEE admin and getting lot of complaints fronm developers that BI Server services are not stopping. I was adviced by my senior that i have to kill thresads in the server.
I followed what you told but when i open the RPD, i am unble to open cache in either offline or online modeHi,
- Unable to open cache due to you already disabled cache (usage tracking - nqsconfig.ini file) cache diabled that why you can't able to open cache
just make sure
[CACHE]
ENABLE = YES;
C:\Oracle\Middleware\instances\instance1\config\OracleBIServerComponent\coreapplication_obis1 (obiee11g file path ref)
- unable to stop biservices? if that case you can kill it different ways, (stop bi services/ctrl +c on services/task manager/FMW (console/EM)/ services.msc etc) which way did you tried?
(which version did u tired)
Thanks
Deva -
HT204382 hello somebody, how can I open/listen to yousendit file on mac? thnx
hey guys how do I open/listen to yousendit file on mac? Thnx
To me you have left out the critical information on how you are connected to this other Mac.
Presumably if you can see the other Mac's drive you can start your iTunes with the option/alt key held down and guide it to the iTunes Library.itl file on the other computer. That is starting from its library, not just using its media. You do not do anything with preferences, Do not touch those. Many people make the mistake of thinking that is how you use media in another location. You can point all you want but iTunes will not look there. It will, though, start storing all your files you add to the iTunes library in that other location from that point on which will result in a fine organizational mess. -
Who can tell me how to finish to filter content of file by Minifilter?
Hi
who can tell me how to finish to filter content of file by Minifilter?
Thanks
www.jiangkai.netThis is a huge project at your level of knowledge expect multiple people for 18 months to 3 years to complete it. You may want to look at the OSR kit for doing this
https://www.osr.com/monadnock/ It is expensive but it means you would have a product this year.
Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com -
I keep getting an err=-36 error on a few songs from an albumn I just peurchased on itunes. Any suggestions on how to finish getting the songs?
Thanks for the response...
I thought it might be the AV, but it downloaded about 30 tracks without problem, its only the video that was problematic.
I've tried again tonight and got a security alert that the firewall was blocking it. So I've disabled the firewall and the intrusion prevention, logged out and logged back in, but it still keeps displaying a -3259 error.
Unfortunately its a work laptop, so I can't disable the AV as a whole because its locked down, but as I say, I've downloaded music videos in the past without this issue.
I can't get an iTunes Network Diagnostics report as iTunes shuts down everytime I try to run it.
Maybe you are looking for
-
Error while invoking BPEL from ESB
Hi All, I am try'n to invoke BPEL process from ESB services ,where my BPEL process contains a webservice which has an input parameter of type ,a customized bean. I am hitting with the below error <env:Envelope xmlns:env="http://schemas.xmlsoap.org/so
-
ISight camera "in use by another application"
Hello. I'm having trouble using my built-in iSight camera in my brand new MacBook Pro. I can get the thing to work while using iMovie 08, but it won't work with Photo Booth, iChat, or iMovie HD. The very first day I had the computer, it worked with P
-
How can I delete my TECHNET account? Social. Forum. ALL TECHNET.
I only ask because I just created a second account, somehow, while trying to set up alerts for my first account, which I still have no idea what the password is. I asked them to send a password reset but still haven't received it. In the process, now
-
I can't use iTunes balance for my in game purchases.
i tried to make an in game purchase and it keeps declining it. I have plenty of money in my iTunes account to cover it. Please help me.
-
I have a CP6 lesson which is essentially two parallel branches, with only the following slides in common: A "Welcome" slide A slide where the learner chooses his branch A "Congrats! You completed the test" slide A "You did not answer the questions c