The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by georgio]

I read your book and still have a few questions.
Question 1
Assume we have 2 click buttons on a form
where each creates a new thread and new instance of the class.
Are they thread safe even if running the same time?
Question 2
Assume we have an app and one class that calls a static method in another
class where it opens an SQL conn and returns a DataTable.
Lets us say that 2 or more threads simultaneously want to execute the static
method.
Does it mean that thread 1 needs to finish before thread 2 starts to execute or
booth can execute it the same time in a thread safe enviroment?

Thanks
import-bot (20211) [Avatar] Offline
#2
Re: Instance and static methods Question
[Originally posted by alan]

Good questions.

1) If the thread only accesses the newly created instance of the class then
nothing bad (deadlock, race conditions, etc) can happen.

2) A method should only be marked as static if it is thread safe. The way it
wouldn't be is if it referenced a static data member directly or indirectly
(via another static method). Unless some sort of locking mechanism is
involved you really don't need to worry about the timing of the calls.

I hope this answers you questions, if not, let me know and I'll try again.


Alan
import-bot (20211) [Avatar] Offline
#3
Re: Instance and static methods Question
[Originally posted by georgio]

You answered my questions.

Thanks Alan

PS
Very good work on the book