Difference between Lock and synchronize - synchronize

In an interview I was asked about the difference between Lock and synchronize.
Which will I should prefer.
Logically I find both as same. We can achieve all the task using any of them. But not able to answer what he wants to listen.

Locking and Synchronize achieve the same thing, but synchronize is less efficient. You can read more about why synchronize is expensive in java from this answer here: Why are synchronize expensive in Java?

Related

Why does spring batch's MongoItemWriter not use org.springframework.data.mongodb.core.BulkOperations?

I would think it would perform much better. Is there some guarantee I'd lose using that?
I see no reason why it could not use bulk operations. Feel free to open an issue and contribute the improvement if you want.
Is there some guarantee I'd lose using that?
No, you should have the same results.

How to control events scheduling in Anylogic?

Is there a way to manually schedule the events in AnyLogic? or does the order of creating the model plays a role in that?.
I am creating a complex system which currently not behaving in the same order I am expecting. I looked at AnyLogic help and Stuart Rossiter explanation but, I was not able to draw answers for these two questions.
My approach to the problem is to use FIFO in the experiment with a statechart that is knotted with guards for each state (true if related are all complete ). And I was thinking to use a manually programmed time parameter for the whole model to order the events exactly as I want. I am not sure that this is the right approach or if I will work. Please guide me on that matter.
Thanks InAdvance;
These are my answers:
Yes, there is a way to control the events manually (synchronizing).
Its done by creating several events and ordering their
trigger/re-occurrence times similar to the simulated phenomena.
No, of you are using manual synchronizing, and I don't know about Asynchronous modeling
the approach mentioned in the question did not work :).

Async NSURLConnection with delegate pattern

I know this question has been asked a lot of time and a lot of suggestions exist on the net. But i am still not able to conclude what is the right way.
After ASIHTTPRequest becoming obsolete, i think it is not advisable to use any third party libraries(though AFNetworking is really good), hence i am trying to build a one on my own.
I want to have following features in it Asynchronous concurrent
connections
Support of delegate methods to track connection progress
Support of doing authentication
Ability to cancel any connection and restart
I did came across multiple recipes using NSOperation, GCD, NSBlockOperation, NSRunLoop, etc. Also i did check the code of AFURLConnectionOperation but it is hell lot of a code which i think can be over kill in many situations.
Can anyone suggest me the optimum and minimalist way to achieve my requirements?

How to work collaboratively with Matlab?

For a project we have to write a Matlab simulation and would like to split the work over several persons. As there are some non-professional programmers involved and we are dealing with a short project we want to keep it simple and use Dropbox, so no version management system involved.
What are possibilities to do this? How do we best split the functions? How do you split the program into several files?
Use version control so that you can keep track of who broke what, and commit at regular intervals so that there is a point to version control.
Design the program such that different people can work on it at the same time. Split it into several files which you can independently test for correctness. Have a professional programmer be responsible for the backbone (main function, class definition). Require consistent interfaces and documentation, so it's easy to stick it all together.
Talk to one another frequently. It doesn't have to be large formal meetings in many cases, just turning around and saying "hey, can you look at this?" is often enough. You all need to know who works on what, and where they stand, so that you know who to talk to in case there are questions. It's just so much faster to solve an issue by talking to the person involved rather than by trying to understand their code.
I would use version control - it saves lots of problems in the long run.
Git is good in that there is no central repository - and so everyone owns their own version.
This, in my experience is liked by 'non-programmers' as they like to fiddle (and break) their version.
And git clone http://whatever, as a method of obtaining a distribution is probably as easy as it gets.
And you will need to know when changes were made. For example: you find a bug and are not sure if you need to rerun the previous simulations or not (when was the bug introduced? - does it affect such and such a simulation?). Without version control finding bugs is a major stress because you cannot be sure of the answers to these questions.

Do I need to use DDD, Unit of Work, Repositories or something similar for simple web apps?

I'm working on a simple eCart system using .net4 (c#). I've been doing a lot of reading about Unit of Work Pattern, Repository Pattern, and Persistence Ignorance. I think I have a grasp on the strategy and benefits to building my layers this way, but for my simple app I'm wondering if it's necessary and if anyone can point me towards good architecture for my scope.
Please correct me if I'm wrong - the main benefits to using repositories are to create fewer trips to the DB and to separate application architecture from DB architecture. IE - what's good for DB performance isn't always good for application design so it's best to design what's best for both and then create an interface between the two.
So here's the question - I want any business transaction that occurs to be saved to the DB as soon as it occurs, so there doesn't seem to be a point in queuing data in repositories and then saving it immediately. Why not just save it directly?
Are there other benefits of DDD that I'm missing or would it be over engineering to build out such a robust architecture for every simple project that comes along? Thanks for any help.
Do you need to use [insert pattern here]: Nope When it comes right down to it, the best practice is always the one that gets your application done, and meets the time, monetary, and technical requirements.
But if you take the "lets just get it done" approach, then be aware of the Technical Debt you might be incurring.
Also there are a lot of reasons to use some of these patterns (and they don't always have to do with performance), particularly the Unit Of Work pattern. This has more to do with the requirements and restrictions that often come with ORM's and such. These issues can be a bit complex, but I suspect as you begin to implement some of these things you'll start to realize what those issues are and come to understand why these patterns are useful.
Agree with CodingGorilla. Patterns are great unless they conflict with YAGNI.
If every transaction needs to be written immediately (that is, if you have potential contention between the actions of two users) then you will need a queuing mechanism or you can use the underlying transactional mechanism of whatever data repository you might be using (e.g. SQL)