Solved

VB6, ActiveX server and threads

Posted on 2000-02-25
8
704 Views
Last Modified: 2008-03-10
Hi

I want to create an ActiveX server using VB6 that keeps some open connections to an Oracle server.

Many clients will create instances of the server on the same machine in the same time.

Each client will try to get an unused connection. If all the connections are used - it will wait. If he gets a connetion - it locks it until he finishes the query.

I need the array of boolean flags(used/not used flag) to be shared for all the instances. Managed to do it by declaring the array in Moudle.

Will each instance use another thread/process (I want the queries be executed in the same time)??

Do I need to use Mutex/Shemaphore/Critical Sections to protect the access to the shared memory?

What's the meaning of the threads number in Project->Options??

Thanks,
Saar Carmi
0
Comment
Question by:saar2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2558088
If you want all apps to access the same flags within the object then you need to set the Instancing property of your object to be be SingleUse or PublicNotCreatable. See the VB Help documentation for the Instancing property for full details.
0
 
LVL 1

Accepted Solution

by:
macu earned 300 total points
ID: 2558386
If you use a single thread (thread pool of 1), all instances will share the same global data, however object method calls will be serialized. If you use a thread pool of > 1 or thread per object, not all objects will shared the same global data (although some may in the thread pool > 1 case.)

Here's another method:

Use a thread pool and set the number of threads to the number of connections you want to allow. Have 'global' data  (in '' because the different threads won't share it) of a single boolean. Have your connection type object set the flag on creation and reset the flag on termination. Before setting the flag however, the object should check if it is already set, if it is it should not allow a connection, but can poll the flag until the object(s) it is sharing the thread with completes (and terminates.) NB, you may want to change where this flag is set/reset in case the clients won't destroy the object when they are finished with a connection. Also, you will have to decide how/whether you want the object to tell the client that a connection is not currently available.

However, doesn't MTS do all this for you? Why not use that instead?
0
 
LVL 4

Author Comment

by:saar2
ID: 2561003
How does the MTS help me?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 4

Author Comment

by:saar2
ID: 2561584
Adjusted points to 300
0
 
LVL 4

Author Comment

by:saar2
ID: 2561585
I decided that I don't want any client to wait - if there is no available connection I will create another one.

I thought that all the objects share the global memory so I could make a "manager" that controls the number of connection by closing some after not being used for a while.

This cannot be done with thread pool/thread per object ('cause they don't share any memory.

Any other suggestion?

0
 
LVL 1

Expert Comment

by:macu
ID: 2564124
But making use of the fact that instances on different threads do not share global memory is one way of getting around this (as described previously.) NB, the method I described is a bit flawed, you would need to have more than just a boolean globally to allow for queues of objects waiting connections, so that they will gain the connection in the correct order.

However, if you are going to create a new connection for each client, what is the question now?
0
 
LVL 4

Author Comment

by:saar2
ID: 2565899
I have read a book about MTS with VB and it solved all the problems.

Thanks.
0
 

Expert Comment

by:nuwi
ID: 7800715
Could you tell which book was it ?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question