Sharing an output stream from more than 1 thread.
I have a problem, an ObjectOutputStream is giving me a nullpointerexception.
I have a thread which connects to a server application and uses object input/output streams to communicate. This thread will deal with any incoming requests from the server concurrently from the main program. I presumed you could use the same Socket connection that was created in this thread to send objects from other threads (for example the main thread) but I think I presumed wrong.
This is part of the class which runs as a separate thread:
public void connect()
try
mainSocket = new Socket(hostName, hostPort);
in = new ObjectInputStream(mainSocket.getInputStream());
out = new ObjectOutputStream(mainSocket.getOutputStream());
catch(UnknownHostException e)
System.out.println(e.getMessage());
catch(IOException e)
System.out.println(e.getMessage());
public void run()
connect();
while(true)
// (Not complete)
public boolean verifyEmployeeName(String employeeName)
boolean answer = false;
try
out.writeObject(Server.protocol.VERIFY_EMPLOYEE);
out.writeObject(employeeName);
answer = in.readBoolean();
catch(IOException e)
return answer;
}The verifyEmployeeName() method is called externally from the main thread and generates the IOException at out.writeObject(Server.protocol.VERIFY_EMPLOYEE); (or the first point at which the socket is used). Anyway my question is; do you have to create a new socket for each thread (bear in mind I haven't yet put in synchronization features) or is this nothing to do with that?
Very grateful for any help you have to offer.
alex.p wrote:
Anyway my question is; do you have to create a new socket for each thread (bear in mind I haven't yet put in synchronization features) Not necessarily. But you'll have to sequentialise the communication.
Create a communication thread. Give it the control over the socket. Have it expose a BlockingQueue that takes some form of "tasks". As a thread, that communicator polls its queue, and executes the tasks. Other threads post their tasks on the queue and wait until they're completed. Look for clues in the java.util.concurrent package.
Similar Messages
-
Facing problem to upload MRP output PO from more than one user
We have 11 users in our company. but we can upload MRP output PO from only one user. we need to upload from more users... please help
Hi Hitul,
Query is not clear.
MRP output will be planned order or purchase requsition. Purchase requsition further converted to purchase order. Are you using any Z developed program for uploading the Purchase Orders (PO) in system ? If so there might be some restriction coded in the program for upload by authorized user id which colud be maintained in any Ztable. Please check and come back. If my understanding is wrong please eleborate your requirement.
Thanks & Regards,
Ramagiri -
Hi,
I am trying to read data from more than one file at once. The files are different types e.g. one is a text file one is an xml file like so, StudentInformation.txt, CollegeInformation.xml. The files are all stored in one place, in this case on the D drive of
a local computer. I am trying to locate any files in the D drive with a file extension of .txt or of .xml (there may be more than two of these files in the future, so I'm trying to allow for that). Then I want to open all of these files, extract the information
and output all the information in one display window. I want all the information from these two or more files to be displayed together in the display window.
Here is the code so far. It is throwing up errors.
//Load from txt or xml files
private void btnLoad_Click(object sender, RoutedEventArgs e)
IEnumerable<string> fileContents = Directory.EnumerateFiles("D:\\", "*.*", SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x))
.Where(x => x.Extension == ".xml" || x.Extension == ".txt")
.Select(file => ParseFile(file));}
private string ParseFile(FileInfo file)
try
using (StreamReader sr = new StreamReader(file.FullName))
string line;
while ((line = sr.ReadLine()) != null)
//Logic here to determine if this is the correct file and append accordingly
lbDisplay.Items.Add(line);
return line;
catch (Exception ex)
// Let the user know what went wrong
MessageBox.Show("The file could not be read: ");
MessageBox.Show(ex.Message);
The error it throws up is:
Error 1
'BookList.MainWindow.ParseFile(System.IO.FileInfo)': not all code paths return a valueThis is the Small Basic programming language so moving to a C# forum.
But you need all paths to return a value, including if an exception is called and it jumps to the catch, perhaps just:
// Let the user know what went wrong
MessageBox.Show("The file could not be read: ");
MessageBox.Show(ex.Message);
return ""; -
Stream to more than 1 location at a time?
Is it possible to stream to more than one Airport Express at a time? I'd like to be able to hear my itunes in the family room AND upstairs (and also on my office computer) so I don't have to switch locations all the time as I move through the house. Is that possible?
As currectly designed, iTunes does not support streaming of music to more than one Airport Express at a time.
The only workaround is to log on to your Mac under two different user names. Run iTunes under each user name, with each running copy streaming to a different Airport Express. Switch between running users with the "fast user switching" feature of the MacOS. Problem with this workaround - if you want to play the same music to both Airport Express devices, it is virtually impossible to get the sound from the two in sync. -
Row should be locked before getting an output stream from an attribute
I have table Worker with photo attribute (its database type is ORDSYS.ORDIMAGE, entity attribute type is OrdImageDomain).
I use standard display and edit renderer for displaying and changing ord-image attribute.
If I add new worker and set him photo, everything is OK.
But if I edit some existing worker and set them photo, while posting to database exception is thrown.
This problem began some time ago, after made some changes (like upgrade JDev, changing some AM configuration properties, and so on...), but I ca't reproduce right behaviour.
I use JDeveloper 9.0.3.2, database is Oracle8i Release 8.1.6.0.0, I tried reserved and stateful AM mode both (the same bad result), pesimistic locking.
Error occures inside Tomcat 4.1.27 and OC4J both.
Does anybody know any hint about this error...?
Than you very much
Jan
PS. Error message datail:
oracle.jbo.DMLException: JBO-26041: Failed to post data to database during "Update": SQL Statement "JBO-25040: Row should be locked before getting an output stream from an attribute.".
at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:4542)
at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:4422)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:3544)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:2290)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2232)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:1527)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:1693)
at oracle.jbo.html.jsp.datatags.CommitTag.doStartTag(CommitTag.java:45)
## Detail 0 ##
oracle.jbo.JboException: JBO-25040: Row should be locked before getting an output stream from an attribute.
at oracle.jbo.domain.BaseLobDomain.getOutputStream(BaseLobDomain.java:729)
at oracle.ord.im.OrdDomainUtil.loadAndSetProperties(OrdDomainUtil.java:656)
at oracle.ord.im.OrdImageDomain.saveToDatabase(OrdImageDomain.java:2325)
at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:4521)
at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:4422)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:3544)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:2290)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2232)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:1527)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:1693)
at oracle.jbo.html.jsp.datatags.CommitTag.doStartTag(CommitTag.java:45)Thanks for replay.
Yes, I use JDev wizard generated BC4J JSP app (it was generated inside 9.0.2 and then migrated to 9.0.3).
I changed inside it many things, but I thing no important.
I have for example copying record to history while editing, but when I disable it, the same problem occures.
I changed database - 8.1.7 to 9.2.0.2.0, but the same problem.
Any hint?
Thanks for any comment. -
Streaming to more than one Airport
I have installed the update for iTunes (the new version beign 6.02) which advertises as allowing simulatneous streaming to more than one airport express (up to three). When I try to select more than one express station (by holding the shift key while selecting the additional location) I receive a prompt that the location does not support playback as a group. How do I configure the express to support playback as a group.
Many thanks in advanceTry selecting "multiple" from the speaker selection menu, that use the window that pops up to check off the speakers you want. It seems to work here. ( I do hav the latest AEX update.) What's cool is that even the computer speakers stay in sync with the remote speakers; something that Airfoil couldn't do.
-
On some pages the text from more than one paragraph stack up on top of each other, like writing something then writing something else over the top of it. Some pages will run text and pictures together, like a car rear-ending another or a train pile up. Other pages will cut an image or text short, i.e. it will display a portion of the top of the image or text but not the rest. This happens on Amazon for example, the section where it says "Customers who looked at this also looked at" will allow only a certain amount of the upper portion of the description immediately below the picture of the product but below that section everything is fine until I get to another section displaying more products and their descriptions and then it cuts the bottom portions off again. I've noticed this behavior mostly in the sections with product photos, the text sections seem okay. YouTube also displays this behavior. It's even doing it on this page right now. Below this box I can read "The more information you can provide the better chance your question will be answered " , but directly below that in the next sentence I can see the start of it with "Troublshootin" and the "Automatically Add" in a green field covering the "g". The next clear text is "A window will open in the top corner. Click Allow, and then click Install. If the automated way doesn't work, try these manual steps." I tried turning of pre-fetching, clearing history, cookies, and cache, scanning for malware with Avast and Windows Defender all to no avail. It began when I upgraded from dial up to DSL via AT&T Uverse. I have a Motorola NVG510 modem. The modem was replaced an hour ago along with new dedicated lines and DSL/Phone splitter from the box by an AT&T technician to make sure my incoming lines were up to par. He ran a connection test and verified everything is up to standards. IE does not display this behavior. I am running Firefox20.0.1 and all previous versions have acted the same way since I upgraded to DSL about 3 months ago.
If you have increased the minimum font size then try the default setting "none" in case the current setting is causing problems.
*Tools > Options > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
Make sure that you allow websites to choose their fonts.
*Tools > Options > Content : Fonts & Colors > Advanced: [X] "Allow pages to choose their own fonts, instead of my selections above"
It is better not to increase the minimum font size, but use an extension to set the default page zoom to prevent issues with text not being displayed properly.
You can use an extension to set a default font size and page zoom on web pages.
*Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
*NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/ -
how do i find which Apple ID is associated with music in my iTunes? When I sync with my iPad and iPhone it tells me I have music, apps etc from more than five IDs. I am asked for PW for a number of now extinct accounts.
Go to Settings/icloud. The Apple ID at the top of the screen is the only one you need to be concerned about. That one MUST be a working ID, and you must know the password for it, or you will be unable to use the phone if it ever crashes, you want to update it, or you want to sell it.
-
Can I have in one iphone 5 music from more than one itunes accounts? My daughter and I have our music in the same pc. She and I have iTunes accounts. I have not been able to load in my ophone with my itunes acct music that she purchased in her account. I have not been able to do this. Thanks
iTunes Match is not sharable across Apple IDs. The best way to get the music on her iPad is to leave hers signed into her Apple ID on the iTunes Store and sync via USB.
-
Reporting from more than one infocube and also from multiple ODS
Hi all,
Someone please help me in these issues.
How can we do reporting from more than one cube ( if data in all the cubes are required, but only a few fields from each cube). And how to do the same with more than one ODS.
Thanks in advance,
SekharHi Sekahr
Can u jus create a multiprovider.
Before creating the multiprovider..Just check the Common charcterstics avilable in
all the ods based on that give the mapping ..
and then once u have completd the creation of multiprovider execute the same in
the tcode <b>Listcube</b> and then create the querys as per the user thats it...
Regards
R M K
Assining points is the only way of saying thanx in SDN *** -
Can takes from more than one track be comped at the same time?
Greetings,
I know that this question has been asked recently in this forum (http://discussions.apple.com/thread.jspa?messageID=9527542�), but I don't think that the respondents completely understood the question... Or perhaps I did not understand the suggested solutions to the problem. I will ask the question in a slightly different way...
Suppose that I record guitar with 2 microphones (a pickup mic, and a room mic). The first microphone is recorded onto track 1, the second microphone is recorded onto track 2. Multiple takes are done in this manner. When it comes time to comp the tracks, how is it done? Can the takes from more than one track be comped together at the same time? I have tried to do this by grouping both tracks together, but it does not work.
Any suggestions?
Thank you.You had the right idea grouping the tracks together. You must make sure that in the group settings, the box titled "region selection (edit)" is checked. This will allow you to make the same cuts (or in this case, swipes) on all regions in the group.
-
JDBC-XI-FILE scenario. How to extract data from more than one table in JDBC
Hi,
I was asked a question like in JDBC-XI-FILE scenario........ How to extract data from more than one tables (i.e from JDBC system) ?? What is the logic to do the same ??
I am not sure whether this is a valid question..........but any help in this regards is highly appreciated.
Regards
KumarHI,
Yes it can be possible ,please see the following links
JDBC Receiver with Oracle Stored Procedures
configuring jdbc adapter with multiple tables
RFC -> XI -> JDBC Scenario Updating Multiple Tables
/people/alessandro.berta/blog/2005/10/04/save-time-with-generalized-jdbc-datatypes
JDBC Adapter multiple Selects
https://www.sdn.sap.com/irj/sdn/advancedsearch?query=jdbc%20with%20multiple%20tables&cat=sdn_all
Regards
Chilla.. -
How can i play a movie in keynote from more than 600 seconds between other slides in a automatic loop
The maximum duration available for an automatic presentation in Keynote is 600 seconds.
The alternatives are to export a QuickTime video, use other presentation applications, a media server player or digital signage application. -
My itunes library has organically grown from more than one itunes account (all paid for by me) but all now on a separate computer. If I upgrade to iTunes match will I have to pay for each account or just once, for the computer?
No. Provided the computer that you use to upload / match your Songs is authorised to play all of the Songs all works well - once complete you can download Song files that will play on your libraries / other computers without each computer having to be authorised.
-
How to delete contents from more than 1 table
How to delete the entire contents from more than 1 table in a single query.
It is very urgent,
Thanks in advance
JohnGoto SE11 ->Open table ->Utility ->data base utility ->delete database table.
BTW, Do not do it.
Thanks,
Ashish
Maybe you are looking for
-
I can not open my photo, opened in lightroom, in photoshop CS4. a plug-in camera raw xx is missing. Advice to update does not work. There is no plug-in in the map photoshop plug-ins.
-
Need help with actively replacing text in SVG
I am new to Dreamweaver, Illustrator and SVG. Also, I do have a firm understanding of HTML but limited knowledge of Javascript and other languages. I am trying to create a website where the user is able to type in a form field (or something to that
-
FINDER WONT OPEN. NEED SUPPORT ASAP
I ACCIDENTALLY MOVED ALL FILES FROM FINDER CONTENT RESROUCES INTO THE TRASH. NOW BECAUSE ALL THE FINDER RESOURCE IS IN THE TRASH FINDER WONT OPEN. ERROR 10810 AND NOW TRASH WONT OPEN COS IS ALSO A FINDER. PLEASE HELP ASAP.
-
Table or conbination of tables having Fields BUKRS and EKORG
Hi Can you please help me out in finding out a table in SRM having fields BUKRS ( company code) and EKORG (purchasing organization ) so that i can fetch the vendors with the above selection . It can be a combination of tables also .
-
Collapse all Folders in Finder
Is there a way to collapse /all/ folders in Finder instead of hunting them down and closing all of them one by one? Thanks.