Blog Post

Synchronous vs Asynchronous

,

You’ll hear these terms thrown around in programming all the time, but what do they mean and why do we care? Starting with simple definitions first:

Synchronous

  1. occurring at the same time; coinciding in time; contemporaneous; simultaneous.
  2. going on at the same rate and exactly together; recurring together.
  3. Physics, Electricity. having the same frequency and zero phase difference.
  4. Computers, Telecommunications. of, relating to, or operating using fixed-time intervals controlled by a clock (opposed to asynchronous ).
  5. Aerospace. geostationary.

 

Asynchronous

  1. not occurring at the same time.
  2. (of a computer or other electrical machine) having each operation started only after the preceding operation is completed.
  3. Computers, Telecommunications. of or relating to operation without the use of fixed time intervals (opposed to synchronous ).

 

Honestly that’s less helpful than I expected. So I’m going to try my own definitions related specifically to running code along with an example of each.

Synchronous – Code that runs one one line at a time. Each line of code is completed before the next one starts. If an external call is made then it is completed before the next line of code runs.

Asynchronous – Code that is launched and runs separately from the initial code. If a SQL job is launched from inside a batch of code (using sp_start_job for example) then the job is running in parallel (at the same time as) to the remainder of the batch of code.

Ok, so why do we care?

Because sometimes we want to be able to start a piece of code without having to wait for it. Agent jobs and service broker are great ways to do this btw. For example inserting data into a table that needs to be processed but you don’t want to have to wait on the processing to commit the insert. On the other hand there are times when we want to start a job and wait for it to finish.

There are a lot of ways to handle this from both directions and it really depends on what you are doing. The important thing is to remember that the concept exists. That both options exist and know which you need.

Filed under: Microsoft SQL Server, SQLServerPedia Syndication Tagged: development, microsoft sql server

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating