Professional Web Applications Themes

Thread-safe Code - ASP.NET Web Services

I am considering using web services as an alternative to DCOM/COM+ components for middle-tier logic. I have developed COM+ components in the past, using VB6, but they were obviously STA, so threading was a minimal concern. My question is, how concerned should I be with making my code thread-safe when using a VB or C# web service? Will ASP.Net automatically serialize calls so that each instance will ignore the others? I am not maintaining any component state between calls, and the web service component itself is fairly simple and single-threaded. Thanks, Erik J. Sawyer Webmaster Kingsport City Schools [url]www.K12K.com[/url]...

  1. #1

    Default Thread-safe Code

    I am considering using web services as an alternative to
    DCOM/COM+ components for middle-tier logic. I have
    developed COM+ components in the past, using VB6, but
    they were obviously STA, so threading was a minimal
    concern.

    My question is, how concerned should I be with making my
    code thread-safe when using a VB or C# web service? Will
    ASP.Net automatically serialize calls so that each
    instance will ignore the others? I am not maintaining
    any component state between calls, and the web service
    component itself is fairly simple and single-threaded.

    Thanks,
    Erik J. Sawyer
    Webmaster
    Kingsport City Schools
    [url]www.K12K.com[/url]
    Erik J Sawyer Guest

  2. #2

    Default Re: Thread-safe Code

    Thread safety is a concern when a resource is shared among multiple threads
    and these threads try to access the same resource at the same time. If you
    don't do this then you are probably thread safe. If you do have a shared
    resource it may still not be a problem is all the accesses are read-only.
    The problem usually occurs when one or more threads are trying to modify the
    resource simultaneously, or when one is modifying it while other threads are
    reading it. It may not always be obvious when you are accessing a shared
    resource - that is part of your job as a developer.

    One simple approach to making your code thread-safe is to take a lock on a
    private object whenever you access the shared resource.


    "Erik J Sawyer" <ESawyerN-o-S-p-a-m.K12K.com> wrote in message
    news:078001c3890a$da2bfce0$a101280aphx.gbl...
    > I am considering using web services as an alternative to
    > DCOM/COM+ components for middle-tier logic. I have
    > developed COM+ components in the past, using VB6, but
    > they were obviously STA, so threading was a minimal
    > concern.
    >
    > My question is, how concerned should I be with making my
    > code thread-safe when using a VB or C# web service? Will
    > ASP.Net automatically serialize calls so that each
    > instance will ignore the others? I am not maintaining
    > any component state between calls, and the web service
    > component itself is fairly simple and single-threaded.
    >
    > Thanks,
    > Erik J. Sawyer
    > Webmaster
    > Kingsport City Schools
    > [url]www.K12K.com[/url]

    Dave Guest

  3. #3

    Default Re: Thread-safe Code

    The only shared resource I plan to access currently is
    SQL Server; I will ensure that any multi-table updates
    are encapsulated in a transaction, and I use stored procs
    to return Identity for any ID columns.

    - Erik J Sawyer
    >-----Original Message-----
    >Thread safety is a concern when a resource is shared
    among multiple threads
    >and these threads try to access the same resource at the
    same time. If you
    >don't do this then you are probably thread safe. If you
    do have a shared
    >resource it may still not be a problem is all the
    accesses are read-only.
    >The problem usually occurs when one or more threads are
    trying to modify the
    >resource simultaneously, or when one is modifying it
    while other threads are
    >reading it. It may not always be obvious when you are
    accessing a shared
    >resource - that is part of your job as a developer.
    >
    >One simple approach to making your code thread-safe is
    to take a lock on a
    >private object whenever you access the shared resource.
    >
    >
    >"Erik J Sawyer" <ESawyerN-o-S-p-a-m.K12K.com> wrote in
    message
    >news:078001c3890a$da2bfce0$a101280aphx.gbl...
    >> I am considering using web services as an alternative
    to
    >> DCOM/COM+ components for middle-tier logic. I have
    >> developed COM+ components in the past, using VB6, but
    >> they were obviously STA, so threading was a minimal
    >> concern.
    >>
    >> My question is, how concerned should I be with making
    my
    >> code thread-safe when using a VB or C# web service?
    Will
    >> ASP.Net automatically serialize calls so that each
    >> instance will ignore the others? I am not maintaining
    >> any component state between calls, and the web service
    >> component itself is fairly simple and single-threaded.
    >>
    >> Thanks,
    >> Erik J. Sawyer
    >> Webmaster
    >> Kingsport City Schools
    >> [url]www.K12K.com[/url]
    Erik J Sawyer Guest

Similar Threads

  1. Replies: 0
    Last Post: May 23rd, 05:09 PM
  2. #40098 [NEW]: php_fopen_primary_script() not thread safe
    By wharmby at uk dot ibm dot com in forum PHP Bugs
    Replies: 7
    Last Post: January 12th, 02:35 PM
  3. Replies: 0
    Last Post: January 11th, 12:03 PM
  4. #40079 [NEW]: php_get_current_user() not thread safe
    By wharmby at uk dot ibm dot com in forum PHP Bugs
    Replies: 2
    Last Post: January 9th, 11:27 PM
  5. #39710 [NEW]: getprotobyname is not thread-safe
    By dave@php.net in forum PHP Bugs
    Replies: 0
    Last Post: December 1st, 10:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139