One of the tasks of CORBA's object adaptors is the management of concurrent access to its server objects. Therefore, incoming calls will be routed (depending on the actual configuration) to one or more worker threads concurrently accessing the server object.
This example makes implicit multithreading within the CORBA server process visible.
Show multithreading within the CORBA server process.
module MultiThread { interface Greetings { string hello( in string a_strmyName); }; }; |
public class GreetingsImpl: MultiThread.GreetingsPOA { public override string hello( string _a_strmyName ) { Monitor.Enter(this); System.Console.WriteLine("Call 'hello', Parameter '{0}', is processed by thread {1}", _a_strmyName, Thread.CurrentThread.Name); Monitor.Exit(this); // Sleep 2 Sec. Thread.Sleep((int)2000); return "End call"; } } |
// The Threadpool m_thdPool = new Thread[] { new Thread( new ThreadStart( runRequest)), new Thread( new ThreadStart( runRequest)), new Thread( new ThreadStart( runRequest)), new Thread( new ThreadStart( runRequest)), new Thread( new ThreadStart( runRequest)) }; // Start the threads int iCnt = 0; foreach( Thread oThd in m_thdPool) { oThd.IsBackground = true; oThd.Name = "CltRequestThd-" + iCnt.ToString(); iCnt++; oThd.Start(); } |
public void runRequest() { MultiThread.Greetings m_oIGreetings; Ics.CORBA.Object oGreetingsObj = m_oOrb.string_to_object( "file://c:\\MtThd.ior"); m_oIGreetings = MultiThread.GreetingsHelper.narrow( oGreetingsObj); string strRet = m_oIGreetings.hello( Thread.CurrentThread.Name); Monitor.Enter(this); Console.WriteLine("{0} Thread{1}", strRet, Thread.CurrentThread.Name); Monitor.Exit( this); } |
a.) Start the Server.
b.) Start the Client.