While the table is locked, no writes can occur to the table. Any triggers attempting to write will hang until they get a lock-wait timeout.
You can use pt-online-schema-change to do a table restructure without blocking access to the original table.
Otherwise, configure a pair of servers in master-master replication, do the optimize table on the second master, then swap their roles and do the optimize table on the first master.