"Portable" way to do message passing between threads?

(I posted this on the Apple Developer Forums already, but since that forum is only accessible to registered and paid iPhone developers, I thought it would be nice to put it here as well so as to get some more potential eyeballs on it. I apologize if this kind of "cross-posting" is not kosher/is frowned upon around here.)
Hey everybody,
"Long-time listener, first-time caller," heh.
I've been working for the past 2-3 months on my very first iPhone app. Actually, what I've been working on is a framework that I plan to use in an iPhone app of my own but which I am also trying to write for the "lowest-common-denominator" so that I (and others) can use it in other apps written for both Mac and iPhone.
Not only is this my first time writing an iPhone app, it is my first time writing for any Apple platform. In fact, it is my first time using Objective-C, period. I cannot stress this enough: I am a "n00b." So go easy on me. I also have not worked with threading before this, either, on any platform, so the learning curve for me here is rather significant, I'm afraid. I am NOT afraid of either taking the time to learn something properly OR of rolling up my shirtsleeves and working. However, on account of my experiences so far, I am finding myself (not to flame or anything!) quickly becoming frustrated by and disillusioned with not so much Objective-C itself, but the Foundation frameworks.
So with that said, read on, if you dare...
The basic idea behind my project is that the framework I am writing will present an API to developers which will allow them to write client apps that interact with a particular network appliance or network-aware embedded system. I already have my basic set of classes up and functioning, and the framework works to my satisfaction both on MacOS and iPhoneOS. The platforms I am targeting are MacOS X Tiger 10.4 and later, and iPhoneOS, and up until this point, I've managed to keep a codebase that works on all of the above.
What I wanted to do next was add some multithreaded goodness to the mix. (Woe is me.) I have asynchronous network socket I/O working within the main thread, and it, in fact, works a treat. In my test app on the phone, I've managed to keep the UI nice and responsive by using the main thread's runloop efficiently. But even though TCP async I/O works fine within the main thread, I want to be able to split out and offload the processing of any data received by the app from the appliance to its own thread. (It is possible, and even desirable, for an application using this framework to be connected to multiple appliances simultaneously.)
My idea, in order to try to keep things as simple and as clean as possible, was to implement a wrapper class that presented my other main class as an "actor." So, rather than instantiating my main class, one would create an instance of the wrapper class which would in turn control a single instance of my main class and spawn its own thread that the network connection and all data processing for that particular connection would run within.
(I hope I'm making sense so far...)
Out of the gate, writing a subclass of NSThread sounds like the logical design choice for an "actor-type" thread, but because I was trying to maintain Tiger compatibility, I stuck with +detachNewThreadSelector:etc.
Once I decided to pursue the actor model, though, the main problem presented itself: how to best pass messages between the main thread and all of the "actor" threads that might be spawned?
I stumbled upon -performSelector:onThread:withObject:, and knew instantly that this was exactly what I was looking for. Unfortunately, it doesn't exist on Tiger; only its much more limited little brother -performSelectorOnMainThread:withObject: does. So I kept looking.
All of the pre-Leopard documentation, tutorials, and sample code that I read indicated that to pass messages between threads, I needed to basically pretend that the threads were separate processes and use the expensive Distributed Objects mechanism to get messages back and forth. Unfortunately, even if that WAS a desirable option, iPhoneOS does not have any support for DO! Grrr...
Finally, I thought I found the answer when I ran into a third-party solution: the InterThreadMessaging library from Toby Paterson (available @ http://homepage.mac.com/djv/FileSharing3.html). In this library, the author basically implemented his own version of -performSelector:onThread:withObject: called -performSelector:withObject:inThread:. Sounds close enough, right? And actually, it is pretty darn close. It's made to do exactly what it sounds like, and it does it in a platform-neutral way that works on pre-Leopard systems as well as iPhoneOS, using Mach ports instead of DO.
(...wellll, ALMOST. I discovered after I built a small test app around it that it actually isn't "iPhone-clean." The author used an NSMapTable struct and the NSMap*() functions, which don't exist in iPhoneOS, and he also implemented the handlePortMessage delegate method, but although iPhoneOS has NSPort, it DOESN'T have NSPortMessage. GAAARGH. So I took the time to replace the NSMapTable stuff with NSValue-wrapped objects inside of an NSMutableDictionary, and replaced the handlePortMessage method implementation with a handleMachMessage method, which took some doing because I had to figure out the structure of a Mach message, NO thanks to ANY of the available documentation...)
Once I started using it, though, I quickly discovered that this implementation wasn't up to snuff. My "actor" class and my main thread will be passing a ton of messages to each other constantly whenever there is network activity, and with InterThreadMessaging, I found that whenever activity started to ramp up, it would collapse on itself. This mostly took the form of deadlocks. I found a note that someone else wrote after experiencing something similar with this library (quoted from DustinVoss @ http://www.cocoadev.com/index.pl?InterThreadMessaging):
"It is possible to deadlock this library if thread A posts a notification on thread B, and the notification on B causes a selector or notification to be posted on thread A. Possibly under other circumstances. I have resolved this in my own code by creating an inter-thread communication lock. When a thread wants to communicate, it tries the lock to see if another thread is already using the InterThreadMessaging library, and if it can't get the lock, it posts a message to its own run-loop to try again later. This is not a good solution, but it seems to work well enough."
So I tried implementing what he described using a global NSLock, and it did help with some of the deadlocks. But not all. I believe the culprit here is the Mach ports system itself (from the NSPortMessage documentation for -sendBeforeDate:):
"If the message cannot be sent immediately, the sending thread blocks until either the message is sent or aDate is reached. Sent messages are queued to minimize blocking, but failure can occur if multiple messages are sent to a port faster than the portís owner can receive them, causing the queue to fill up."
InterThreadMessaging in fact calls -sendBeforeDate: and exposes the deadline option, so I tried setting a really short time-to-live on the Mach messages and then intercepted any NSPortTimeoutExceptions that were thrown; upon catching said exceptions, I would then re-queue up the message to be sent again. It worked, but Performance. Was. A. Dog. At least the message queue wouldn't be full indefinitely anymore, causing the main thread to block, but during the whole time that these messages were expiring because the queue was full and then being re-queued, either the main thread was trying to send more messages or the actor thread was trying to send more messages. And as far as I can tell, the Mach ports queue is global (at the very least, there is seemingly only one per process). The message would get through with this model...eventually.
JUST IN CASE the problem happened to be something I screwed up as I was rewriting portions of the InterThreadMessaging library so that it would compile and work on the iPhone SDK, I substituted in the original version of the library in my Mac test app to see if any of these problems became non-issues. I found that both versions of the library -- mine and the original -- performed identically. So that wasn't it.
Finally, in frustration I said, "screw it, I'm going to try it the Leopard way," and replaced all of the method calls I was making to InterThreadMessaging's -performSelector:withObject:inThread: with calls to Foundation's native -performSelector:onThread:withObject: instead, changing nothing else within my code in the process. And wouldn't you know: IT WORKED GREAT. Performance was (and is) fantastic, about on-par with the non-threaded version when only dealing with a single connection/instance of my class.
So, in the end, I was able to do nothing to salvage the InterThreadMessaging implementation of cross-thread method calling, and as far as I can tell, I'm out of (good) options. And thus my mind is filled with questions:
How is the Leopard -performSelector:onThread: method implemented? I'm guessing not using Mach ports, given that I didn't have the same blocking & deadlocking problems I had with InterThreadMessaging. Is it possible to re-implement this Leopard+ method in a similar manner as a category to NSObject under Tiger? Or is it possible, perhaps, to increase the size of the Mach ports queue so that InterThreadMessaging works at a sane level of performance? Or -- I'm getting desperate here -- is there any way that I could trick -performSelectorOnMainThread: to target a different thread instead? (I am assuming here that -performSelectorOnMainThread is implemented under-the-hood much like the new -performSelector:onThread: is implemented, but with a hard-coded NSThread pointer built-in to the code, and that the new method just exposes a more flexible interface to what is basically the same code. I'm probably wrong...) Is there another third-party library out there that I've missed that fits my requirements for being able to do message-passing between threads in an efficient and portable manner?
I refuse to believe that there is no way for me to maintain compatibility with all of the platforms I wish to support without having to resort to making preprocessor #ifdef spaghetti out of my code. And there SURELY has to be a better way of doing cross-thread message passing in Tiger without using Distributed Objects, for Pete's sake! Is this really how people did it for years-on-end since the dawn of NeXT up until the advent of Leopard? And if there really, genuinely wasn't another alternative, then what is up with the lack of DO in iPhoneOS?? Does Apple seriously intend for developers who have good, solid, tested and working code to just chuck it all and start over? What if there was some aspect of DO that previous implementations relied upon that cannot be recreated with simple -performSelector:onThread: calls? (I don't know what those aspects would be...just a hypothetical.) I mean, I can understand needing to write new stuff from scratch for your UI given how radically different the interface is between the Mac and iPhone, but having to reimplement back-end guts such as something as elemental as threads...really?!
I do laud the inclusion of the new method in Leopard as well as the new ability to subclass NSThread itself. But for those of us that need to support Tiger for one reason or another, some of these restrictions and omissions within iPhoneOS seem like rather pointless (and frustrating) roadblocks.
As I hope is obvious here, I have tried to do my homework before throwing up my hands and pestering y'all. If you have the patience to deal with me, please tell me what I am missing.
Thanks for taking the time to read,
-- Nathan

Thanks again for your patience. Comments below.
etresoft wrote:
It is pretty unusual that anyone would want to call perfomrSelector on any thread other than the main thread.
What I described in my original post was not a worker thread, but an "actor."
It is hard for me to answer this question because there are so many options available to do "message passing". The fact that you think there are so few tells me that you really aren't sure what you need to use.
I didn't say there were few options for message passing. I said there were few options for message passing that fit my criteria, which are that any potential solutions should both A) work efficiently and with good performance, and B) be available both pre-Leopard AND on the iPhone. -performSelector: ain't available before Leopard. Distributed Objects is overkill. Kernel Mach messages apparently have a high overhead, too, as my experience with the third-party library I wrote about in my original message shows.
...consider notifications.
I thought notifications couldn't be posted across threads, either. How do I post a notification to another thread's default notification center or notification queue from a different thread?
The notification center is owned by the process. Each run loop can listen for just the notifications it wants. You don't "pass" or "send" notifications, you run then up the flagpole for all to see.
I am aware of how to use notifications. The documentation for NSNotificationCenter clearly states that "In a multithreaded application, notifications are always delivered in the thread in which the notification was posted, which may not be the same thread in which an observer registered itself."
So, again, I don't see how one thread can post a notification in such a way that the observer's registered method is executed in another thread (posting notifications "across threads"). This probably isn't a big deal if you are using mutexes (assuming you don't actually care which thread carries out the task associated with the notification posting), but as I said before, this is not what I'm after.
I don't know what you are really after.
Allow me to attempt to explain a second time, in a more concise fashion.
My app will have multiple, persistent TCP connections open, one connection per remote device. The user will be able to select a task to execute on a particular device that we have a connection open to, and get back from the application real-time updates as to the progress or results of the execution of that task. In certain cases, the length of the task is infinite; it will keep executing forever and sending back results to my application which will update its display of the results every second that ticks by until the user STOPS that particular task.
This can be done simply using async I/O in the main runloop, sure. But if I were going to thread this so that I could be processing the results I've received back from one *or more* remote devices while also doing something else, given that I will only have one (persistent) connection open to any given remote device that I'm interacting with (that is to say, I won't be opening up a separate TCP session for every single task I want to execute on a single device simultaneously), it makes sense _to me_ to implement this as I've described: with every connection to each remote device getting its own thread that lasts for the lifetime of the TCP session (which could be the entire time the application is running, times however many devices the user wishes to be connected to while in the app). I won't be spawning a new thread for every task the user wishes to ask a remote device to do.
This is why (I think) I need bi-directional messaging between the main thread and each of these threads dedicated to a given remote device that we have an active session with/connection to. The main thread needs to be able to tell remote device X (which already has a running thread dedicated to it) to do task A, and then get real-time feedback from that remote device so that the main thread can be displaying it to the user as it is coming back. Same with remote device Y running task B, simultaneously. At any time during the execution of these tasks, the user needs to be able to tell my app to stop one of these tasks, and the main thread needs to send that message to one of the remote devices via that device's dedicated thread.
This is why I am talking about this in terms of the "actor model," and not the "worker thread model," because the former model seems to fit what I want to do.
-- Nathan

Similar Messages

  • Parent Child message passing

    I was hoping you guys could give me a little advice on message passing between child and parent classes.
    I'm working on a pretty basic booking system, with a front end GUI for data entry. Currently i have a basic JFrame GUI class, the back end of the system that deals with storing/manipulating data and other such stuff, and a controller class that contains both the GUI class and the back end classes.
    My goal was to keep the GUI and back end separate, however this is causing me problems when it comes to passing data around...
    I want to be able to search through customer details, and return the matching ones, but i'm stuck as to how I pass the message back properly.
    Basically i am asking how can i get a child class (the GUI) to pass messages back to its parent (the controler class)?
    I know i could just put the controller class in as an attribute of the GUI class, but i'd like to avoid that if at all possible.
    i'm pretty sure that it is possible as i remember a lecturer teaching us something similar to that at one point, but that was several years ago now and i do not remember any of the syntax or keywords.
    any links or advice would be greatly appreciated
    thanks

    Christof,
    yes keep the controller in control... the GUI should not be "coupled" to it.
    ** I think what you're after is the Data Access Object Pattern. It's extremely clever. Yep, I'm a fan.
    ** Yep, just pass back the dataset as an object, probably as a collection (maybe ArrayList) of data-transfer-objects... checkout the collections tutorial...
    Keith.

  • Send and receive messages between threads

    Hi All,
    I am new to Java programming, I am planning to implement a simple chat server (Clients will connect from Android phones). My idea is to listen on the server on a specific port, and as soon as a connection is received on that port a new thread would be created. So far so good.
    The confusion is, I want threads to send messages to each other, for example user1 wants to send a text message to user2. How can I send the messages between threads?
    I am thinking of creating a hashtable which will hold username(key) and the queue object (value). For each connection(thread) I will store a new queue object in the hashtable - Each thread will continuously listen to its own queue. If any thread wants to send message to other, it can fetch the relative queue object and push the message in it. (Each thread knows which thread to call).
    Please advice if there is a better approach to this problem, or if I there is best practice for such problems.
    Thanks,
    Rahil

    sja wrote:
    There may be some reason to pass messages between threads, but so far I can't see it in the spec. Threads are for making several things happen at the same time. If you want to send a message from one user to another, that's one thing happening, and, unless there is some technical reason for it, no need to hand the message between threads.
    If you have a bunch of threads listening to sockets, those are not users, they are socket listening threads. The thread is not the user."Passing messages between threads" is a rather broad and ill-defined concept. However, for some valid interpretations, it's a very common and useful thing to do. The most obvious is the producer/consumer example that the OP is talking about.
    The "message" here could be the unit of work that's enqueued by one thread and dequeued by another. This message is passed simply by the enqueue/dequeue acts.
    Or the "message" could be the producer informing the consumer of the fact that there is a unit of work for him to do. This is accomplished by the underlying queue's blocking mechanism, e.g. notifyAll().

  • Is there a way to view earlier messages in a thread without going through each day? Also, can you make a photo album from the same text thread without going back to the beginning?

    Is there a way to view earlier messages in a thread without going through each day? Also, can you make a photo album from the same text thread without going back to the beginning?

    Turn Settings > General > Accessibility > Zoom to ON.

  • Simple distribuited computing appl. with RMI (message-passing system ?)

    hi,
    I had success with several exercises to create remote objects, and now
    I would like to apply RMI mechanism to work in my application on a small net.
    My problem is to make the connection to a database (derby) embedded
    in a copy of the application (installed as server) ,accessible  to other copies
    of the same application (installed as clients).
    I studied the problem and, in my simple mind of beginner,
    I understood that for it to work (as first) it is necessary to create a system
    of messaging communication between the agents on the net, to allow the clients
    applications know the name of object they have to use...
    I don't know if my idea is correct, and I am not sure if this is the right direction
    to begin the new part of my work ...
    Before beginning my work here, I should like to read some tutorial
    or read some other type of information  that can guide me to go
    forward in this new problem.
    Any help should be appreciated.
    thank you
    regards
    tonyMrsangelo

    hi Peter ,
    thank you for answering me,
    I read the Derby documentation (Derby Developer's Guide) where is wrote:
    When a Derby database is embedded in a Java application, the database is dedicated to that single application.
    If you deploy more than one copy of the application, each application has its own copy of the database and Derby software. I am not sure to 100%, but think to interpreter those words in the way that different applications cannot share the same information on the tables of an only one dataBase...
    For this reason I decided to use Remote Objects to access to database.
    I think that, for my simple case, it is enough to implement a communication using a ServerSocket and a Socket.
    Now I have difficulty with this problem...
    I wrote two small programs to manage the communication between a Socket and a ServerSocket.,
    but I am not able to do they work correctly.
    I post here the code of both .. I would like to know what is wrong because they don't communicate each the other.
    Implementation of the program Server :
    * this class implements a simple Gui
    public class ServerXnetworkingTest extends JFrame {
    // I cannot write the code here because the number of characters allowed
    } // class ServerXnetworkingTest
    class SocketServerImplementation {
        Socket socket;
        int portNmbr = 4444;
        BufferedReader inStream = null;
        PrintWriter outStream = null;
        ServerXnetworkingTest serverXnetworkingTest;
         * @param serverXnetworkingTest
        public SocketServerImplementation(ServerXnetworkingTest xxx) { // constructor
            serverXnetworkingTest = xxx;
            ServerSocket serverSocket = null;
            try {
                serverSocket = new ServerSocket(portNmbr);
            } catch (IOException ex) {
                Logger.getLogger(SocketServerImplementation.class.getName()).log(Level.SEVERE, null, ex);
            // Waits the connection of the client
            // (dice al programma di aspettare per un tempo indefinito fino a quando
            // un cliente non si connette alla porta).
            Socket incoming = null;
            try {
                incoming = serverSocket.accept();
            } catch (IOException ex) {
                Logger.getLogger(SocketServerImplementation.class.getName()).log(Level.SEVERE, null, ex);
            //  After a connection is set with this port,:
            // - una richiesta attraverso la rete questo metodo restituisce
            //   un oggetto Socket che rappresenta la connessione che e' stata stabilita.
            // - si puo' utilizzare questo oggetto per ottenere gli steram di input
            //    e di output, come sotto indicato.
            try {
                inStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                outStream = new PrintWriter(socket.getOutputStream(), true);
            } catch (IOException ex) {
                Logger.getLogger(ServerXnetworkingTest.class.getName()).log(Level.SEVERE, null, ex);
            String inputLine;
            try {
                while ((inputLine = inStream.readLine()) != null) {
    //                JOptionPane.showMessageDialog(serverXnetworkingTest, msg);
                    System.out.println("Server ----> letta linea di testo = " + inputLine);
            } catch (IOException ex) {
                Logger.getLogger(SocketServerImplementation.class.getName()).log(Level.SEVERE, null, ex);
    //        outStream.print(inputLine);
    //        outStream.flush();
        } // constructor
         * this function is  called pushing a button to write text in the output stream
         * @param msg
        void messageSender(String msg) {
            outStream.print(msg);
            outStream.flush();
           // outStream.write(msg); // ???
            //outStream.flush();       // ???
        } // stringMsgSender()
    } // class SocketServerImplementation {
    Implementation of the program Client :
    * this class implements a simple Gui
    public class ClientXnetworkingTest extends JFrame {
    // I cannot write the code here because the number of characters allowed
    } // class ClientXnetworkingTest
    class SocketClientImplementation {
        Socket socket;
        int portNmbr = 4444;
        BufferedReader inStream = null;
        PrintWriter outStream = null;
        ClientXnetworkingTest clientXnetworkingTest;
         * @param serverIpAddress
         * @param xxx
        public SocketClientImplementation(String serverIpAddress, ClientXnetworkingTest xxx) { // constructor
            clientXnetworkingTest = xxx;
            outStream = null;
            inStream = null;
            try {
                // constructor
                socket = new Socket(serverIpAddress, portNmbr);
            } catch (UnknownHostException ex) {
                Logger.getLogger(ClientXnetworkingTest.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(ClientXnetworkingTest.class.getName()).log(Level.SEVERE, null, ex);
            // http://forums.sun.com/thread.jspa?forumID=31&threadID=595806
            // trovato con : use InputStream with Strings
            try {
    //            inStream = socket.getInputStream();
                inStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                outStream = new PrintWriter(socket.getOutputStream(), true);
            } catch (IOException ex) {
                Logger.getLogger(ClientXnetworkingTest.class.getName()).log(Level.SEVERE, null, ex);
        } // constructor
         * this function is called pushing a button to write text in the output stream
         * @param msg
        void messageSender(String msg) {
            outStream.print(msg);
            outStream.flush();
         //   outStream.write(msg); // ???
         //   outStream.flush();       // ???
        } // stringMsgSender()
    } // class SocketClientImplementation {any help is welcome
    thank you
    regards

  • Collapsed view: how to see "most recent unread message" instead of "first unread message" in a thread in Mail

    Hey all,
    I use the inbuilt Mail-software on my Macbook with Lion 10.7 and I constantly overlook new messages in a thread, as I organize by conversation and usually have all my threads in 'collapsed view'. For some reason Mail seems to prefer showing the 'first', i.e. the earliest unread message as the one message that I see in collapsed. If there are newer messages already in the thread, I don't see them, unless I un-collapse the thread. I find this really unintuitive and annoying, my inbox seems far more static than it really is.
    Is there any way to change this and have Mail show me the most recent unread message as the message I see in collapsed view?
    I appreciate any advice.
    Thanks, Carl
    PS: BTW, I have the same problem on my iPhone, double props to you if you can solve it for both Mail and iPhone!

    Mail
    Preferences
    Viewing
    Check put most recent message at top

  • Hi I am having problems downloading and updating apps on my iPad and iPhone. The message cycles between waiting and loading then I get an error message saying unable to download app. Eventually,after many attempts it works.

    Hi Guys - for a few days I have been having problems downloading and updating apps on my iPad and iPhone. The message cycles between waiting and downloading then eventually says unable to download app. Sometimes after many attempts it wil eventually work. I tested it on an old iPhone 3G and got the same problem so it is not an iOS 5 issue. My WI-FI connection is working fine. I was wondering if this is an App Store problem? Anyone else in the UK having this problem?

    Hi John
    iTunes Support wasn't of any use to me.
    I have also been having another problem - with BBC iPlayer and other video streaming not working due to insufficient bandwidth, despite my overall download speed being consistently around 50Gb.  This is also affecting AppleTV downloads
    I am using Virgin Media as my ISP, and was wondering whether you do as well.  This might be the common thread.
    -Bernard

  • New forum feature: A button or option to jump to the first unread message in a thread.

    It would be handy if we had a way to open a thread and jump to the first unread message in the thread. This is especially usual when reading very active threads and it would save us some time getting back to the point in the discussion where we left off.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

    altenbach wrote:
    Another variation of this would also be useful: ....
    Actually, we already have that, but I tend to forget. We simply need to click on the nonzero number all the way on the left.
    LabVIEW Champion . Do more with less code and in less time .

  • I am looking for a way to sync my calendars between Microsoft Outlook Calendar and My IPhone 4?

    I am looking for a convenient way to synchronize my calendars between my email account and Microsoft Outlook to my gmail account and Iphone 4s

    you are asking about Microsoft products and using a laptop, not a workstation Mac Pro.
    The Numbers and Pages Apple Communities. or MS Community if you want those.
    Importing and Exporting, but Numbers and Pages will not do a SAVE into other formats by default, and therefore have to keep using Export which is messy.
    Changing your own thread midstream may not be ['thread hijack'] but it is like having the rug pulled out by changing the subject on us.

  • What's the best way to share JE environments between servlets?

    Hi, I'm happily serving requests for the same webapp (so single servlet) which uses multiple JE environments. In my case I have an environment for each db, one of these environments is a login details only db. Things work great, three questions though:
    1. Right now I'm keeping environment/entity store references in global vars (everything below entity store, views etc. is created and discarded for each request), is there a better way?
    2. When I want to add a new app (so additional servlet) - how can I make sure the login environment is shared across servlets, to take advantage of shared cache etc?
    3. As indexes are thread safe, is it considered best practice to store index refs. in global vars. and have each incoming thread (in a servlet) share these vars. or should each request build the object refs. it uses and discard accordingly?
    Hoping the above makes sense.
    PhilQ.

    Yes, EntityIndex objects are also thread-safe. Really only EntityCursor objects are not.
    The entity objects themselves are not owned by JE. You will have problems if you have multiple threads changing them concurrently (if one thread is changing an entity object's properties and another thread is storing it, for example). However, it is up to you if you want to share entity objects between threads; there is nothing wrong with that, since there is no interaction with JE. But your app will need to enforce thread safety, perhaps by using them only in a read-only fashion, for example.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Sharing socket object between threads - Is any sync required?

    For example, a thread receives (listens) datagram packets at incoming socket and forwards them downstream through another datagram socket. Another thread listens packets at this second socket and forwards the data via the first socket. It is possible that two threads invoke methods of the same socket (one is receiveng while another is sending). This situation is not described in the DatagramSocket manual. I beleive there is underlying synchronization at the OS kernel level. Can I relay on it? Thanks.

    I expected some critics for using old plain sockets instead of nio :)You should use NIO if you have hundreds of connections. If you have a small number of connections and want a simple implementation use blocking IO as you have.
    If you can have different
    threads reading or writing at once eg two readingor
    two writing then you need to use synchronisation.Shouldn't this be stated by the API designers somewhere?It is probibly covered in a tutorial or example somewhere.
    You have a different input and output stream. There is a lock on each. This is your best hint.
    Theoretically, nothing prohibits sending UDP packets in race conditions.
    In fact, this is what my program
    does - it respondes to different clients using one
    (server) datagram socket. The responses are produced
    by multiple threads. I suppose that java does not
    involve any state variables; thus, beleive that the
    system can accomplish the synchronisation unnecesary
    at the application level.That depends on how you build and send your messages. If each part of the message can be sent in one hit and the order does not matter you are fine.
    If you have a single object shared between threads, then all members are shared, not just static variables.

  • [Feature Request] Message URLs in Threaded or Flat View

    Hi.
    I view topics in Thread View, but I suppose the following is applicable to Flat View as well. I would like to be able to easily copy/paste URLs for individual messages in the thread. The way I have to do it now is:
    1. Copy/Paste the thread URL (i.e. http://discussions.apple.com/thread.jspa?threadID=XXXXXX).
    2. Right-Click or Ctrl-Click in the Reply link of the message and choose Copy Link (i.e. http://discussions.apple.com/post!reply.jspa?messageID=YYYYYY).
    3. Type '#' after the URL in 1 above, paste the link from 2, and remove everything up to the message number (i.e. http://discussions.apple.com/thread.jspa?threadID=XXXXXX#YYYYYY).
    It would be nice to have a direct link to the message in the message itself, so that I could accomplish the same doing step 2 only.
    TIA.

    Eme,
    How do you assume in the world that u know
    what i read ?
    You're missing the point (again). I didn't assume anything. It's you who have assumed what was I talking about.
    Maybe I am just new, you think that may be the case?
    Is there anything in what I've said that makes you think so?
    mind reading is not your forte
    You'd be really surprised in this regard if you knew me...
    give it up at least when it comes to me, Okay.
    OK, no problem. May I ask (again) where have you seen "option click" mentioned?
    Yikes. Condesending ;~P
    Maybe, but I don't think so. At least, not until you tell me where have you seen "option click" mentioned?
    It was in reference to Ali Brown's post, which i
    looked at without your permisssion, off course.
    Of course. Now, where exactly?
    TIA.

  • Table for Total messages passed through XI

    Hi Experts,
    I want count of total messages passed through XI in one day.
    At present I am doing it using SXMB_MONI but it is very slow and takes lot of time to calculate.
    Anybody knows the table which holds this information, so I can get the information in one shot.
    Thanks in advance
    Shri

    This thread ( Michal's reply ) will point you to the tables in which messages are stored in XI,
    In Which Database Table the Messages are Stored in XI
    Regards
    Bhavesh

  • Portable way to call Stored Procs. which return a ResultSet (MySQL/Oracle)?

    Hello!
    I have developed a Java application which calls stored procedures, some of which return a ResultSet (always one).
    I need to support more DBMS vendors, so I used the standard JDBC syntax to call the stored procedures ({call storedProcedure(?,?)}).
    I developed the code using MySQL, but succeded to call SQL Server 2000 stored procedures changing only the driver (that's the purpose of JDBC, right?).
    Now I need to support the Oracle DBMS, but I can't find a way to create a stored procedure which returns a result set and allows me not to change the already stable Java code.
    How could I achieve this result? Should I use some other Oracle object, say a function?
    By the way, I searched the Internet, but only found solutions which would've made me change code. This is definitely not portable
    Thank you very much for your help!
    PS: Some of the stored procedures return both a ResultSet AND OUT parameters.

    Hello and thanks for your reply, jwenting.
    However, keeping useless "philosophy" out of this thread, please just let me clarify that I obviously didn't want portability of stored procedures, I just wanted a standard JDBC to interface with them. I haven't had problems in the past with stored procedures and other DBMSs, I'm having them just now with the Oracle JDBC driver. Since JDBC is meant to be portable, I hoped there was a portable way of calling Oracle stored procedures (or whatever else in Oracle takes inputs and returns output and a ResultSet...). Unfortunately, there doesn't seem to be any, unless I use a commercial driver from DataDirect. I find this a heavy limitation of the Oracle JDBC driver, but, alas, here it is... I'll have to refactor my stable code...
    Thanks again...

  • Can objects be passed between Applets and JSP?

    Can objects be passed between Applets and JSP? If so how? Thanks in advance.
    Scott

    see if this helps,
    http://forum.java.sun.com/thread.jsp?forum=54&thread=136847

Maybe you are looking for

  • Disk full attempting to move files from PC to Mac

    I've just bought a brand new Macbook Air. I'm attempting to move photos, music and some documents from my old acer onto the macbook. However when i've tried to do this, i've found that the disk is full. This disk is the macinstosh HD disk, though the

  • Perspective Selection Tool not working

    I can't figure out why the selection tool won't work.  When active, I can't grab an object to move it and the icon next to the selection arrow is a line with an arrow pointing to the left, like this <–| Any suggestions?

  • Oracle Ultra Search

    I don't know how to modify the interface of Ultra Search Portlet, such as words: Search for, Submit. Please help me. Thanks a lot.

  • How to change time in LINUX

    Dear Experts Please any one tell how can I change time in LINUX machine through Command??? regards PAKISTAN

  • PDF line weight - please help!

    Hi, When I save from InDesign as a PDF any line drawn with the pen tool/circle tool etc stay the same line weight no matter how much I'm zoomed in on the document. For example, I could zoom right out to 25% and the line thickness will still look at t