Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6, ActiveX server and threads

Posted on 2000-02-25
8
Medium Priority
?
731 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 600 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

618 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