Concurrency in Google app engine - java

I have a chat application in google app engine. I am facing the concurrency issues.
When the chat starts from one end, that chat will broadcast to all available agents in the account. When 1 guy responds that guy will take ownership and remove all the remaining guys in that session.
Here i am facing problem with concurrent requests from more than 1 agent response at the same time. At this point each request takes out the remaining agents in the session and no body is there in the session.
I thought this solves with code synchronization. But with multiple instances doesn't work this logic. Since the code is in different servers.
Is there a way to acheive this make synchronize using datastore/memcache.
Please suggest on this.
Thanks in advance.
Govind.

Look at using CAS with memcache, alternately you can use transactions in the datastore and plan control entities with known keys. I don't use java so can't whip up an example , and I can only find api docs for java on cas
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/memcache/MemcacheService.CasValues
but the writeup in python would still explain what is going on .
https://developers.google.com/appengine/docs/python/memcache/#Python_Using_compare_and_set_in_Python

I tried this using Transactions. But some reason it wont work out to me. I dont know the reason. But with Memcache increment/decrement we can solve the problem. These methods are atomic. This is simple and optimistic.
Please go through this group
https://groups.google.com/forum/#!topic/google-appengine-java/wtESRwKCF5U
Thanks for your updates.
Govind.

Related

Java Spring Application Deadlock

I have some general questions about the concept of deadlocks.
I am trying to learn the basics how to learn the basics of building multi threaded applications and I just need some key words and basically point me in the right direction what to look into, since I have problems understanding some basic concepts.
I want to learn how can I programm queues in java so I can hold elements prior to processing. For example, if my application have many notifications, I want them to put them in a queue and process them asynchronously, so they don't access the database simultaneously and avoid DEADLOCKS.
Therefore, I started studying the java.util.concurrent package in Java, but before that I just have some basic questions.
Is the java.util.Queue interface the right approach to this problem?
I have another basic question to a behaviour which I dont understand. Let's assume we have a basic application where multiple users can log in and edit their profile information (Firstname, Birthdate...). If two users are logged in and edit their information simultaneously, then both information need to be peristed in the same user table. Could this lead to a deadlock, since both access the same table? How does Spring handle this?
EDIT:
As I described above, I have an application that handled multiple tasks which produces sometimes deadlocks. I want them to put in a queue and then process each task asynchronously.
I have done some research and I think that the best solution would be to use the Producer-consumer pattern with the ExecutorService with a BlockingQueue like described in this article: https://allegro.tech/2015/05/thread-pools.html
What do you think? I just want some ideas if this solution is good enough for my problem description? Are there better ways to do it?

Database change notification app

I'm about to embark upon writing an android app which notifies the phone's user when an external mySQL DB is updated (add only) with a ticket so that the user can check if the ticket requires his attention (an attempt to reduce the buildup of tickets that he has to trawl through).
From my research, most questions suggest using a PHP web service with my program (written in java) and definitely/maybe/definitely not/it's deprecated using SQLNotification to fire the event. I've also seen something about some bloke called JSON and the brands of SOAP he uses.
What I've been unable to figure out is how all of these frameworks/toolkits/services/things work together.
My question is in two parts:
Is SQLNotification usable? If not, is there a simple way to check for changes (beyond the obvious answer of polling)
How does everything (SOAP, JSON, web service, app) fit together and have I missed anything on the frameworks front (Heard mentions of spring, hibernate, tomcat).
On my experience, I'm relatively fluent in Java, understand the basics of MySQL, am a beginner in PHP and haven't written for android before.
Thanks,
Ben
According to the information you have provided, seems like you have different options:
Push
If you want to go the push way, you will need some central architecture that can take notifications from the database and immediately send them to connected clients. It's not that easy to build such a scheme, would only recommend it if you really need immediate notification. As a start point, look at this sample: http://www.gianlucaguarini.com/blog/push-notification-server-streaming-on-a-mysql-database/
Pull
If you go the pull way (polling), you can have a service working on the phone wich polls every configured time. In that case you will need some stateless service, some simple JSON service would do great.
On both cases, be careful with security, you should secure your channel with ssl and have some decent sort of authentication.
I think a good rule of thumb is saying (it's just based on personal opinion/experience, maybe your decision path has other factors that you have to consider), if your pollig intervals don't need to be lower than 5 minutes, polling will do fine. If you need almost real-time notifications, you can implement the push architecture, but you have to know it will cost more efford to get it working as you have to take care of things like client disconnection, how to handle notifications if a client is not connected, get the real-time notifications from the database, etc.
Hope this helps as a starting point,

Create a user in IronMQ via API

I'm trying to set up a message queue service for an application I am developing.
I already tried AWS SQS, but it doesn't really fit for our needs, mainly for the issues with the FIFO and the limited message persistence.
So I turned to IronMQ, to see how this could work, but I'm already having issues with the creation of users via java APIs.
There's no class dedicated and it seems nobody cares about that. Does anybody know anything about how to do that? Do I have to write my own APIs?
EDIT: as manveru pointed out, I'm talking about tokens, not users.
Another issue is about setting other permissions than "Admin", but I guess I'll confront it later.
Right now, our API doesn't support creating new access tokens. I think it's something that could be really powerful, though (generate a token per server as part of the build process, for example).
I've created an issue in our global issue tracker. If you like, you can follow that to get a notification when something on this front changes. We have a lot of stuff we're working on right now, so I can't even guess at a timeline, unfortunately. :(
Hope that helps!

Databases sync through webservice

I Do not know much about it, but I have a question and I hope you can help me if it is possible.
I need to synchronize two databases, one is a mobile database (SQL Server Compact) and the other a MySQL database. Both have exactly the same tables.
Then, is it possible to synchronize the records via a webservice?
I accept any ideas, suggestions or help.
Many greetings and thanks.
pd: sorry about my english... :)
Have a look at SymmetricDS. It runs as a webservice (tomcat6) and is able to do both one and two way synchronization. It also supports the concept of a single root node and several client nodes.
SymmetridDS is database "transparent", meaning that it can synchronize between databases independent of database type.
It's quick, stable and reliable. The learning curve might be a bit steep when you first dive into it, but it is quite a piece of software once you get the hang of it!
yes.
you need to create a piece of code that can connect to both databases at the same time.
you need to then read them and decide what is different between the two,
then you need to apply changes that make one look more like the other (non-trivial).
You will need to decide which one should be the master, or if both should modify the other somehow.

What is the best way to implement a website where Users can interact together

I am creating a website where users will be able to chat and send files to one another through a browser. I am using GWT for the UI and hibernate with gilead to connect to a mysql database backend.
What would be the best strategy to use so Users can interact together?
I'd say you are looking for comet/AJAX|Server push/etc. See my previous answer on this matter for some pointers. Basically you are simulating inverting the communication between server and client - it's the server that's initiating the connection here, since it wants to, for example, inform the user that his/her friend just went online, etc.
The implementations of this technique change quite rapidly, so I won't make any definitive recommendations - choose the one that best suits your needs :)
COMET is the technology that allows chatting over a web page - It is basically communicating through keep-alive connections. This allows servers to push information to the client.
There are several implementations of this on the client side with GWT.
Most servers nowadays support this, It is also part of the Servlet 3.0 spec (Which nobody has implemented yet)
While COMET is very nice, it's not the only solution! Usual polling with time intervals (as opposed to COMET long polling) is still commonly used. It's also possible to require a manual refresh by the user.
Take Stackoverflow as an example - for most things you must refresh your browser manually to see the changes. I think, it's commonly perceived as normal and expected. COMET or frequent polling are an added bonus.
The problem with COMET is, that it can easily lead to lots of threads on the server. Except, if you additionally use asynchronous processing (also called "Advanced IO"), which is not too well supported yet (e.g. doesn't work with HTTPS in Glassfish v3 due to a severe bug), can lead to problems with Apache connectors etc.
The problem with frequent polling is, that it creates additional traffic. So, it's often necessary to make the polling less frequent, which will make it less convenient for the end user.
So you will have to weigh the options for your particular situation.

Categories