Network application - java

I'm developing a network application, which will handle a lot of transactions, so I'm using INNODB as storage engine & Transactions, so do I need to use a LockTable also?
As I know they don't work together. Please give me the best solution to do it.

Not sure why you are asking about table locking with respect to InnoDB, as it supports row-level locking. I would just focus on making sure your transactions are written correctly and let MySQL take care of the rest.

Related

Oracle database (online) replication

I am a Java guy, I can work with Oracle Database, I know PLSQL, SQL. But I am not good at managing database servers. I think it is a completely different area.
My question is related to database replication. I googled it, found millions of answers but I am still confused.
I could see many times in my professional carrier that developers create complete (complicated) applications to keep sync the source database schema to a target one. It takes time to develop sync apps and very hard to maintain them, especially in case of any data structure modification for example in tables.
I could see that apps built with JPA, JDBC, Spring, myBatis, and PLSQL as well. Usually, they sync DBs during the night, scheduled by Cron, Quartz, Spring, etc. During the sync process usually, the source DB is only available for querying data, not for inserting and DB constraints and triggers are disabled.
These kinds of custom applications always scare me. I do not believe that there is no general, easy, and official way to keep sync two databases without developing a new application.
Now, I got a similar task and honestly, I would like to write zero lines of code related to this task. I believe that there are recommended and existing solutions, cover this topic offered by the database vendors.
That would be great if you can push me in the right direction. I feel that writing another new DB sync application is not the right way.
I need to focus on Oracle Database sync, but I would be happy to know a general, database vendor-independent way.
There are many ways to perform replication in a Oracle Database. Oracle has two replication techniques in the database "Advanced Replication" and "GoldenGate". GoldenGate us the new perferred method of replication which uses the redo logs files from the database. Both methods are geared for a Oracle DBA.
Often application developers will create a "interface" that will move data from one database to other. A interface is a program ( pl/sql, bash, c, etc ) that runs on a cron (database or system) that wakes on a event to move data. Interfaces are useful when data is needed to be process during replication.

Two Spring apps each use jpa to control a single database

Two Spring apps each use jpa to control a single database.
Each Spring app must use a single database.
Will spring.jpa.hibernate.ddl-auto = update work properly?
In my opinion, having 2 applications using directly the same database is a poor design.
Here is a quote from this sofware engineering answer
The more applications use the same database, the more likely it is
that you hit performance bottlenecks and that you can't easily scale
the load as desired. SQL Databases don't really scale. You can buy
bigger machines but they do not scale well in clusters!
Maintenance and development costs can increase: Development is harder
if an application needs to use database structures which aren't suited
for the task at hand but have to be used as they are already present.
It's also likely that adjustments of one application will have side
effects on other applications ("why is there such an unecessary
trigger??!"/"We don't need that data anymore!"). It's already hard
with one database for a single application, when the developers
don't/can't know all the use-cases.
Administration becomes harder: Which object belongs to which
application? Chaos rising. Where do I have to look for my data? Which
user is allowed to interact with which objects? What can I grant whom?
Upgrading: You'll need a version that is the lowest common denominator
for all applications using it. That means that certain applications
won't be able to use powerful features. You'll have to stick with
older versions. It also increases development costs a bit.
Concurrency: Can you really be sure that there're no chronological
dependencies between processes? What if one application modifies data
that is outdated or should've been altered by another application
first? What about different applications working on the same tables
concurrently?
What I would suggest to you is to create a service layer which will be responsible for dealing with database access. This service can then be accessed by differents ways (a REST webservice might be an option).
#Vinod Bokare comment is correct, you must create jar of POJO's and use in both projects,
and #Heejeong Jang, It will be okay if each of our Spring apps has different table areas for insert, update, and delete.

Concurrent access using JDBC in Java

I'm developing a Java Desktop Application using JDBC, and I wanted to manage the concurrent access to the Database. Someone told me to use Sessions but after some research it turned out that Sessions are not possible in Desktop app.
This is why I'm asking for some help. You have any ideas on how to manage this thing.
Thanks
From what you described, I recommend you to check for SQL exceptions while trying to insert or update some row that may be already be changed by someone else. In that case maybe you should reload what your app shows to the user so they have up-to-date data. Another option is to show a user-friendly error.
If your app executes several queries (insert, update) in a row, I suggest using transactions. I think the easiest way to set them in a Desktop app is to use the Spring framework, if you are familiar with it.
It is not clear exactly what you mean by manage concurrent access - do you want to avoid multiple select queries to the DB? In that case using SELECT for UPDATE might be an option. If you are looking for more general method in limiting only single user to access the DB at any time, you will have to roll your own locking mechanism in the code I suppose.
So long as each Thread is using a different Connection, there should not be any concurrency issues in the JDBC. There are any number of ways to achieve this. e.g. ThreadLocal or a connection pool.
I don't see how a single desktop app can be accessed by many users. You can have many copies of a desktop app and each user has their own connections. This shouldn't cause an issue. You need to clarify what your concern is.

Performace enhancement for a Struts2 application(website) with high traffic usage

I wanted to ask that what all things i should keep in mind in order to create a high performance STRUTS2 based web application. It is guaranteed that the site will have a high traffic (i.e. lets assume somewhere around 500,000 requests daily). Also there will be a decent lot of database accesses.
Please comment as i have decided of using the following frameworks (or suggest any better alternatives):
Struts2 + springs and hibernate
Jsp + jquery for views
DWR for ajax calls
Please suggest some performance tuning/enhancement strategies.
Thanks!
Couple of things you can do.
First:
the biggest bottleneck in a website is always the database connection. You will need to make sure that your database is running in a separate cluster and try to do more in each database session when using hibernate. The less DB connections you open/close the faster your application will be.
Use hibernate as much as possible because it has logic to cache queries and such. Also if you have the same information being used across the users session, put it on the session object so that you do not have to query the DB for that info multiple times.
Second:
Use the Spring IOC as much as possible. You should create "service" classes that will be doing your database querying and those classes should be created as singletons and injected into a constructor or setter via Spring IOC.
Third:
Make use of a tool like tiles or wicket. It will allow you to create layouts for your JSPs.
Fourth:
If you have data displaying on the page that takes a long time to load/query, go ahead and load the page with the other data that is fast and then load your slow data dynamically through AJAX. It will give the user the impression that they are receiving an immediate result.
Of course there are many other things you can on the server side. You might want to deploy the application across several node and use a load balancer to route traffic to the least busy node. The amount of caching at the proxy, app server, browser, and database you do will also significantly impact your performance.
Hope that helps!
Since you are using hibernate, you should also look into hibernate performance tuning for which there are lots of resources including these discussions:
https://stackoverflow.com/questions/2460342/books-and-resources-for-java-performance-tuning-when-working-with-databases-hu/2460466#2460466
Hibernate performance
Hibernate performance
Usual hibernate performance pitfall
Avoid bottlenecks in your app design - see these tips from Yahoo.
Run the web server, application server and database server on seperate hardware clusters.
If the performance isn't good enough profile to see what is slowing it down; if there is a bottleneck in the code fix it, otherwise add hardware until it is fast enough.

Synchronizing local database with remote database and vice versa

I am developing a web application with php that needs to synchronize a local mysql database that a java desktop version of the web application is interacting with. At the same time i also need the local db to synchronize with the remote db. How do i do this without using other software like MySQL Compare. I will really appreciate the help. Thanx guys.
You clearly have a significant architecture issue. It needs to be planned very well. Two-way replication clearly isn't going to work unless you have thought it out very carefully and understand how to do conflict resolution and what impact that will have on your application. In particular, you can forget using AUTO_INCREMENT.
For one-way replication, you can use mk-table-sync, or use mysql replication in some way (there are a variety of possiblities).
You can also run another mysql instance on the server, use mk-table-sync to periodically synchronise it locally, and use mysql replication on that. This has some benefits, particularly if there are some tables you don't want to replicate.
You really need to think about how it's going to work, if you plan to do two-way synchronisation. It is possible that you may end up writing custom code to do it, as the conflict resolution mechanism may mandate it.

Categories